This is a port of the C wcwidth function in pure Java. The code is taken from JLine.
While I am publishing this as a library, you might also consider just shading the utility into your own project.
You can find examples of similar utilities in other libraries
<dependency>
<groupId>dev.mccue</groupId>
<artifactId>wcwidth</artifactId>
<version>2024.05.17</version>
</dependency>