mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Fix scanning of 8bit strings where internal and external encodings differ.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23261 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a1076344b8
commit
6edccf2358
1 changed files with 18 additions and 1 deletions
|
@ -72,7 +72,17 @@ static Class NSConstantStringClass;
|
|||
static id _holder;
|
||||
static NSCharacterSet *defaultSkipSet;
|
||||
static SEL memSel;
|
||||
static NSStringEncoding internalEncoding = NSISOLatin1StringEncoding;
|
||||
|
||||
static inline unichar myGetC(unsigned char c)
|
||||
{
|
||||
unsigned int size = 1;
|
||||
unichar u = 0;
|
||||
unichar *dst = &u;
|
||||
|
||||
GSToUnicode(&dst, &size, &c, 1, internalEncoding, 0, 0);
|
||||
return u;
|
||||
}
|
||||
/*
|
||||
* Hack for direct access to internals of an concrete string object.
|
||||
*/
|
||||
|
@ -81,7 +91,7 @@ typedef struct {
|
|||
} *ivars;
|
||||
#define myLength() (((ivars)_string)->_count)
|
||||
#define myUnicode(I) (((ivars)_string)->_contents.u[I])
|
||||
#define myChar(I) chartouni((((ivars)_string)->_contents.c[I]))
|
||||
#define myChar(I) myGetC((((ivars)_string)->_contents.c[I]))
|
||||
#define myCharacter(I) (_isUnicode ? myUnicode(I) : myChar(I))
|
||||
|
||||
/*
|
||||
|
@ -117,6 +127,8 @@ typedef struct {
|
|||
{
|
||||
if (self == [NSScanner class])
|
||||
{
|
||||
NSStringEncoding externalEncoding;
|
||||
|
||||
memSel = @selector(characterIsMember:);
|
||||
defaultSkipSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
|
||||
IF_NO_GC(RETAIN(defaultSkipSet));
|
||||
|
@ -127,6 +139,11 @@ typedef struct {
|
|||
GSPlaceholderStringClass = [GSPlaceholderString class];
|
||||
NSConstantStringClass = [NSString constantStringClass];
|
||||
_holder = (id)NSAllocateObject(GSPlaceholderStringClass, 0, 0);
|
||||
externalEncoding = GetDefEncoding();
|
||||
if (GSIsByteEncoding(externalEncoding) == YES)
|
||||
{
|
||||
internalEncoding = externalEncoding;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue