My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 177: StringTools.fastCodeAt problem, Potential fix included
1 person starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Jun 2012


 
Reported by greg.d...@gmail.com, Jun 2, 2012
StringTools.fastCodeAt (String.cca method) returns negative values for character byte values >127 on cpp.

What steps will reproduce the problem?
	var s = "";
	for (i in 0...10) {
		s = s + String.fromCharCode((120 + i * 12));
	}

	for (i in 0...s.length) {
		trace(StringTools.fastCodeAt(s, i));
	}

What is the expected output? What do you see instead?
other platforms (swf, neko, php, js) would give a sequence like:
 120
 132
 144
 156
 168
 180
 192
 204
 216
 228

cpp currently gives:
 120 
 -124 
 -112 
 -100 
 -88 
 -76 
 -64 
 -52 
 -40 
 -28 

What version of the product are you using? On what operating system?
svn haxe, svn hxcpp, Windows 7 x64

Please provide any additional information below.

POTENTIAL FIX/CLUE
I was able to address this and get results consistent with other platforms by doing the following in hxString.h :
CHANGE line 133:
inline int cca(int inPos) const
    {
          if ((unsigned)inPos>=length) return 0;
          return __s[inPos];
    }


TO:
inline int cca(int inPos) const
{
	if ((unsigned)inPos>=length) return 0;
	return __s[inPos] & 0xff;
}
This works for me, but I'm guessing its not the *right* way to do it?

I assumed that the original return is a signed char or something ( I have no real idea about C++ types). I couldn't figure out how to cast it as unsigned, so went for the bitwise &. I imagine there must be a way to cast to the right type for output?



Jun 3, 2012
Project Member #1 gameh...@gmail.com
I have used (unsgined char *)__s to fix this problem in SVN.
Status: Fixed

Powered by Google Project Hosting