Help - Search - Members - Calendar
Full Version: Token breaking with string8
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
SMF007
Hey all, working on foo_tbar (Title bar display) and I have a small problem. Hopefully someone can help me a little.

I'm trying to parse a string, breaking on a token (a la strtok() ). The string coming in (strSearchCaption) is string8. Idealy I would like to get a string8 off to dump into an array of string8s.

CODE
TCHAR* token = _tcstok(string_utf16_from_utf8(strSearchCaption), ";");


Why do I want to do this? strSearchCaption contains a semi-colon delimited string of window title "words", that the users doesn't want foo_tbar to activate on.
foosion
The expression string_utf16_from_utf8(strSearchCaption) causes the construction of a temporary object which is destroyed after the call to _tcstok, so token contains a dangling pointer. That's at least what would happen, if your code compiled, but I suspect it doesn't, because string_utf16_from_utf8 can only be converted to a const TCHAR * but not to a TCHAR *.

The solution is to copy the string to a mem_block_t<char>, if you want to tokenize the string before converting it, or to a mem_block_t<TCHAR> otherwise (be careful to copy the terminating zero).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.