From 7c335ede527eaf4a3053ef35b1299141d34aaf40 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 19 Nov 2010 05:54:14 +0000 Subject: I now think that this may not work out at all. It looks like if we want proper Unicode handling we'll need to implement a series of codecs and converters as well as tables of codepages and lookups. It'll be interesting, I guess, but it makes me care a lot less about proper encoding. Anyway, UtfString uses shorts instead of chars, so it's a step in the right direction, but still not enough to be able to handle proper UTF-16 encoding, maybe UCS-2 encoding, but... ...that's lame. Bu::FBasicString has been generalized a bit with optimizations from libc for char based strings. It also, unfortunately, still uses char-only functions in several places, those all rely on char casting strings at the moment just to get the thing to compile. Basically, it's not a good UTF-16 solution yet, and it may never be and remain compatible with char based strings. --- src/fbasicstring.h | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'src/fbasicstring.h') diff --git a/src/fbasicstring.h b/src/fbasicstring.h index 7167f4a..af11bb2 100644 --- a/src/fbasicstring.h +++ b/src/fbasicstring.h @@ -39,6 +39,42 @@ namespace Bu template< typename chr, int nMinSize, typename chralloc, typename chunkalloc> class FBasicString; + template + size_t strlen( const chr *pData ) + { + for( size_t tLen = 0;; ++tLen ) + { + if( pData[tLen] == (chr)0 ) + return tLen; + } + return -1; + } + + template + size_t strlen( const char *pData ) + { + return ::strlen( pData ); + } + + template + int strncmp( const chr *a, const chr *b, size_t iLen ) + { + for( size_t iPos = 0; iPos < iLen; iPos++ ) + { + if( a[iPos] != b[iPos] ) + { + return a[iPos]-b[iPos]; + } + } + return 0; + } + + template + int strncmp( const char *a, const char *b, size_t iLen ) + { + return ::strncmp( a, b, iLen ); + } + template struct FStringCore { @@ -1044,7 +1080,7 @@ namespace Bu */ void insert( long nPos, const chr *pData ) { - insert( nPos, pData, strlen( pData ) ); + insert( nPos, pData, Bu::strlen( pData ) ); } void remove( long nPos, long nLen ) @@ -1170,13 +1206,13 @@ namespace Bu if( iStart < 0 ) iStart = 0; if( iStart >= core->nLength ) - return ""; + return (const chr[]){(chr)0}; if( iSize < 0 ) iSize = core->nLength; if( iStart+iSize > core->nLength ) iSize = core->nLength-iStart; if( iSize == 0 ) - return ""; + return (const chr[]){(chr)0}; flatten(); MyType ret( core->pFirst->pData+iStart, iSize ); @@ -1438,11 +1474,11 @@ namespace Bu wordexp_t result; /* Expand the string for the program to run. */ - switch (wordexp (core->pFirst->pData, &result, 0)) + switch (wordexp ((char *)core->pFirst->pData, &result, 0)) { case 0: /* Successful. */ { - set( result.we_wordv[0] ); + set( (chr *)result.we_wordv[0] ); wordfree( &result ); return; } @@ -1954,7 +1990,7 @@ namespace Bu long iLen = vsnprintf( NULL, 0, sFrmt, ap ); Chunk *pNew = core->newChunk( iLen ); - vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); + vsnprintf( (char *)pNew->pData, iLen+1, sFrmt, ap ); core->appendChunk( pNew ); va_end( ap ); @@ -1971,7 +2007,7 @@ namespace Bu long iLen = vsnprintf( NULL, 0, sFrmt, ap ); Chunk *pNew = core->newChunk( iLen ); - vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); + vsnprintf( (char *)pNew->pData, iLen+1, sFrmt, ap ); core->appendChunk( pNew ); va_end( ap ); @@ -1988,7 +2024,7 @@ namespace Bu long iLen = vsnprintf( NULL, 0, sFrmt, ap ); Chunk *pNew = core->newChunk( iLen ); - vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); + vsnprintf( (char *)pNew->pData, iLen+1, sFrmt, ap ); core->prependChunk( pNew ); va_end( ap ); -- cgit v1.2.3