Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Trouble converting v8::String::Utf8Value to sf::String  (Read 4587 times)

0 Members and 1 Guest are viewing this topic.

BubbleChien

  • Newbie
  • *
  • Posts: 1
    • View Profile
[SOLVED] Trouble converting v8::String::Utf8Value to sf::String
« on: January 10, 2015, 11:55:34 am »
Hey!

I've been attempting to convert from v8::String::Utf8Value (which return a char*) to sf::String.

Using a temp std::string with sf::String::fromUtf8 fails.

I'm using the sf::String to feed sf::Text, and while giving the UTF-8 string directly gives the expected extra characters, the result of fromUtf8 shows question marks in squares. The font is fine, tried using a wide string literal and it worked.

Here's what I'm doing at the moment :

JS_RETRIEVE_INSTANCE(sf::Text); // this creates the instance variable
v8::String::Utf8Value str(val); // val is a v8::Local<v8::Value> variable
std::string utf8(*str); // here *str returns a char*
instance->setString(sf::String::fromUtf8<std::string::iterator>(utf8.begin(),utf8.end()));

I'm probably missing some obvious stuff since I haven't really had to deal with encodings in the past, so that would be great if someone's able to help me :)

EDIT: Some changes in the code fixed it, though I have no clue what did; pretty sure the issue was not SFML related.
« Last Edit: February 11, 2015, 07:08:24 am by BubbleChien »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Trouble converting v8::String::Utf8Value to sf::String
« Reply #1 on: January 10, 2015, 12:08:02 pm »
Could you show a complete and minimal example where you simply initialize some char[]s or std::strings (with whatever bytes you have in "utf8" right now) and then actually draw an sf::Text with it?

Incidentally, I'm fairly sure you can pass a std::string directly to sf::Text::setString() without worrying about the conversion yourself.  It's probably safer that way.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Trouble converting v8::String::Utf8Value to sf::String
« Reply #2 on: January 10, 2015, 02:25:06 pm »
Quote
Incidentally, I'm fairly sure you can pass a std::string directly to sf::Text::setString() without worrying about the conversion yourself.
And how would sf::String know the encoding of the source string? You always have to worry about encodings when passing from one string type to another.
Laurent Gomila - SFML developer

 

anything