Help wrapping lines of text (thx.core, wrapColumns)

I need to wrap some text to a given line width.

(I’m using Haxe 4 rc3.)

I found thx.core’s thx.Strings, http://thx-lib.org/api/thx/Strings.html, and it has a wrapColumns function, so I did haxelib install thx.core, added --library thx.core to by hxml, and tried:

import thx.Strings;

class Main {
    public static function main() {
        var content = "line won lorem ipsum
line too lorem ipsum
line tree lorem ipsum
";
        content = Strings.wrapColumns(content, columns = 30);
        Sys.println(content);
    }    
}

but upon compilation I get:

/home/john/haxelib/thx,core/0,43,0/src/thx/Eithers.hx:157: characters 12-17 : Warning : Potential typo detected (expected similar values are Right). Consider using `var right` instead
/home/john/haxelib/thx,core/0,43,0/src/thx/Eithers.hx:164: characters 12-17 : Warning : Potential typo detected (expected similar values are Right). Consider using `var right` instead
/home/john/haxelib/thx,core/0,43,0/src/thx/Iterators.hx:54: character 14 : Unterminated markup literal

That Iterators.hx:54 line is

    #if haxe < 3.3
    return true;
    #end

(character 14 is the less-than sign.)

I fixed this a while ago in a pull request (Fix compatibility with Haxe dev by Gama11 · Pull Request #266 · fponticelli/thx.core · GitHub). It’s been merged but not released, so you just need to install the library from GitHub instead of Haxelib.

Thanks, Jens! It works now, though I also get a whole bunch of warnings about haxe.Utf8 being deprecated and UnicodeString should be used instead.

In https://api.haxe.org/haxe/Utf8.html I don’t see any deprecation note there, but I do see one in the source file itself. Also, I don’t see a UnicodeString anywhere at https://api.haxe.org/, though I do indeed see it in the source at std/UnicodeString.hx.


Incidentally, a few of those deprecation warnings don’t make sense to me:

/home/john/haxelib/thx,core/git/src/thx/Dynamics.hx:208: characters 14-85 : Warning : haxe.Utf8 is deprecated. Use UnicodeString instead.
/home/john/haxelib/thx,core/git/src/thx/Dynamics.hx:220: characters 20-41 : Warning : haxe.Utf8 is deprecated. Use UnicodeString instead.
/home/john/haxelib/thx,core/git/src/thx/Dynamics.hx:226: characters 20-65 : Warning : haxe.Utf8 is deprecated. Use UnicodeString instead.

That file doesn’t contain any use of Utf8… but those lines do call thx.Strings.compare() (which in turn calls the deprecated Utf8 methods). Why would Dynamics.hx cause warnings if it’s not itself directly calling the Utf8 static methods?

api.haxe.org defaults to the most recent stable release:

Why would Dynamics.hx cause warnings if it’s not itself directly calling the Utf8 static methods?

I think that’s just how error positions work with inlined code. Coincidentally there was a commit related to that today: `-D keep-inline-positions` to keep original expr positions of inlined… · HaxeFoundation/haxe@b9df128 · GitHub

1 Like

Btw, you could use -D no-deprecation-warnings if the warnings are annoying and don’t feel like fixing them in thx.core.

1 Like

Ooof! Didn’t notice that in the header. Thanks!

Ah! Thank you.