Hi Ryan, That's true that strnlen() won't work with multi byte chars, which is why I mentioned wcsnlen(). I haven't looked too deeply into that function though, and I don't know if it needs to have an environment setup before it will work correctly.
i.e. does it work with 16bit chars and 32 bit chars? That would be good to know, before we write our own. As for strings that have a null in the middle... there are some fields in the Blackberry that contain two strings in one, using that technique. Does the second string make sense as another field that we should be splitting out? Thanks, - Chris On Tue, Apr 21, 2009 at 05:29:16PM +0800, Ryan Li wrote: > Hi Chris, > > I gave a look at the strnlen() function, and found that it wouldn't work > as I hoped. Since a simple test of strlen("\x40\x00\x40", 4) will give > the return value 1. This simply doesn't work for the strings that have > NULL characters *in the middle*. However, as I can see from the raw SMS > data, there's an instance encoded in 7-byte, having a NULL in the > middle. Maybe the service center lost the data and used NULL as a > replacement. Hence I think the for() loops are necessary. > Incidentally, I wanted to use the ParseFieldString() function in > record.cc at the first time, but didn't work. However, I think it'd be > prettier if we replace the for() loop inside the function with an > equivalent strnlen(). Moreover, or could we just implement the for() > loop detecting NULLs-in-the-middle inside the ParseFieldString() function? > > Chris Frey wrote: > > I used the strnlen() function. See the latest commit in the git tree > > with 'git log -p' > > > > With UCS2 strings, maybe a function like wcsnlen would work for us. > > I'd rather not add for() loops to various parts of the code, if we can > > use strnlen() and wcsnlen(), so I haven't applied your patch. > > Ryan Li > > ------------------------------------------------------------------------------ > Stay on top of everything new and different, both inside and > around Java (TM) technology - register by April 22, and save > $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. > 300 plus technical and hands-on sessions. Register today. > Use priority code J9JMT32. http://p.sf.net/sfu/p > _______________________________________________ > Barry-devel mailing list > Barry-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/barry-devel ------------------------------------------------------------------------------ Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p _______________________________________________ Barry-devel mailing list Barry-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/barry-devel