New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toUtfXString methods to sf::String #501

Closed
criptych opened this Issue Dec 2, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@criptych

criptych commented Dec 2, 2013

Suggest that sf::String should be given toUtf8String (16, 32) methods. I know "convenience" methods are frowned upon, but it would also complement fromUtfX, toAnsiString and toWideString -- and while I can't speak for all, I find myself converting strings to UTF-8 far more often than ANSI.

[My apologies if this has already been suggested, but I couldn't find it in the tracker.]

@LaurentGomila

This comment has been minimized.

Show comment
Hide comment
Member

LaurentGomila commented Dec 2, 2013

@criptych

This comment has been minimized.

Show comment
Hide comment
@criptych

criptych Dec 4, 2013

asUtfX() functions are more complicated since I have to choose a type to return, which is not obvious.
Maybe the user will need a std::basic_stringsf::Uint32, or a QString, or a GString, or even a MyCustomUtf8String, etc. I can handle the first one, but not the others.

It seems to me toAnsi/WideString have set a precedent to return std::basic_strings of the appropriate type:

class String {
    std::basic_string<Uint8> toUtf8String() const; // or possibly std::string
    std::basic_string<Uint16> toUtf16String() const;
    std::basic_string<Uint32> toUtf32String() const;
};

However there's a chance that the target type has a generic fromUtf32 function.

If it does, that's great, but again my point is to make UTF encoding as simple as ANSI encoding, mainly for persistence and transmission. Some libraries, such as PhysicsFS, expect UTF-8 strings as input; and Windows for one uses UTF-16 (or UCS-2? I forget) internally. sf::UtfX::toUtfY is helpful, but cumbersome, as it works only with iterators.

criptych commented Dec 4, 2013

asUtfX() functions are more complicated since I have to choose a type to return, which is not obvious.
Maybe the user will need a std::basic_stringsf::Uint32, or a QString, or a GString, or even a MyCustomUtf8String, etc. I can handle the first one, but not the others.

It seems to me toAnsi/WideString have set a precedent to return std::basic_strings of the appropriate type:

class String {
    std::basic_string<Uint8> toUtf8String() const; // or possibly std::string
    std::basic_string<Uint16> toUtf16String() const;
    std::basic_string<Uint32> toUtf32String() const;
};

However there's a chance that the target type has a generic fromUtf32 function.

If it does, that's great, but again my point is to make UTF encoding as simple as ANSI encoding, mainly for persistence and transmission. Some libraries, such as PhysicsFS, expect UTF-8 strings as input; and Windows for one uses UTF-16 (or UCS-2? I forget) internally. sf::UtfX::toUtfY is helpful, but cumbersome, as it works only with iterators.

@criptych

This comment has been minimized.

Show comment
Hide comment
@criptych

criptych Dec 6, 2013

Terrific, thanks.

criptych commented Dec 6, 2013

Terrific, thanks.

MarioLiebisch added a commit to MarioLiebisch/SFML that referenced this issue Feb 12, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment