mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Added unicode string formatting
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8961 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b4c65db38d
commit
074583906b
8 changed files with 2519 additions and 415 deletions
|
@ -149,6 +149,7 @@ GSArray.m \
|
|||
GSAttributedString.m \
|
||||
GSCountedSet.m \
|
||||
GSDictionary.m \
|
||||
GSFormat.m \
|
||||
GSHTTPURLHandle.m \
|
||||
GSMime.m \
|
||||
GSSet.m \
|
||||
|
|
1849
Source/GSFormat.m
Normal file
1849
Source/GSFormat.m
Normal file
File diff suppressed because it is too large
Load diff
|
@ -45,6 +45,7 @@
|
|||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSObjCRuntime.h>
|
||||
#include <base/GSFormat.h>
|
||||
#include <base/behavior.h>
|
||||
#include <limits.h>
|
||||
/* memcpy(), strlen(), strcmp() are gcc builtin's */
|
||||
|
@ -2133,6 +2134,51 @@ transmute(ivars self, NSString *aString)
|
|||
setup();
|
||||
}
|
||||
|
||||
- (void) appendFormat: (NSString*)format, ...
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
/*
|
||||
* If this is a unicode string, we can write the formatted data directly
|
||||
* into its buffer.
|
||||
*/
|
||||
if (_flags.wide == 1)
|
||||
{
|
||||
FormatBuf_t f;
|
||||
unichar *fmt;
|
||||
size_t len;
|
||||
|
||||
len = [format length];
|
||||
fmt = objc_malloc((len+1)*sizeof(unichar));
|
||||
[format getCharacters: fmt];
|
||||
fmt[len] = '\0';
|
||||
f.z = _zone;
|
||||
f.buf = _contents.u;
|
||||
f.len = _count;
|
||||
f.size = _capacity;
|
||||
GSFormat(&f, fmt, ap, nil);
|
||||
_contents.u = f.buf;
|
||||
_count = f.len;
|
||||
_capacity = f.size;
|
||||
_flags.hash = 0;
|
||||
objc_free(fmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSRange aRange;
|
||||
NSString *t;
|
||||
|
||||
t = (NSString*)NSAllocateObject(NSStringClass, 0, NSDefaultMallocZone());
|
||||
t = [t initWithFormat: format arguments: ap];
|
||||
aRange.location = _count;
|
||||
aRange.length = 0;
|
||||
[self replaceCharactersInRange: aRange withString: t];
|
||||
RELEASE(t);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
- (BOOL) boolValue
|
||||
{
|
||||
if (_flags.wide == 1)
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
#include <Foundation/NSMapTable.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <base/GSFormat.h>
|
||||
#include <limits.h>
|
||||
#include <string.h> // for strstr()
|
||||
#include <sys/stat.h>
|
||||
|
@ -665,6 +666,31 @@ handle_printf_atsign (FILE *stream,
|
|||
return [self initWithFormat: format locale: nil arguments: arg_list];
|
||||
}
|
||||
|
||||
- (id) initWithFormat: (NSString*)format
|
||||
locale: (NSDictionary*)locale
|
||||
arguments: (va_list)arg_list
|
||||
{
|
||||
FormatBuf_t f;
|
||||
unichar *fmt;
|
||||
size_t len;
|
||||
|
||||
len = [format length];
|
||||
fmt = objc_malloc((len+1)*sizeof(unichar));
|
||||
[format getCharacters: fmt];
|
||||
fmt[len] = '\0';
|
||||
f.z = NSDefaultMallocZone();
|
||||
f.buf = NSZoneMalloc(f.z, 100*sizeof(unichar));
|
||||
f.len = 0;
|
||||
f.size = 100;
|
||||
GSFormat(&f, fmt, arg_list, locale);
|
||||
objc_free(fmt);
|
||||
// don't use noCopy because f.size > f.len!
|
||||
self = [self initWithCharacters: f.buf length: f.len];
|
||||
NSZoneFree(f.z, f.buf);
|
||||
return self;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* xxx Change this when we have non-CString classes */
|
||||
- (id) initWithFormat: (NSString*)format
|
||||
locale: (NSDictionary*)locale
|
||||
|
@ -958,6 +984,7 @@ handle_printf_atsign (FILE *stream,
|
|||
return self;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
- (id) initWithData: (NSData*)data
|
||||
encoding: (NSStringEncoding)encoding
|
||||
|
@ -3189,10 +3216,11 @@ handle_printf_atsign (FILE *stream,
|
|||
/* Inefficient. */
|
||||
- (void) appendFormat: (NSString*)format, ...
|
||||
{
|
||||
va_list ap;
|
||||
id tmp;
|
||||
va_list ap;
|
||||
id tmp;
|
||||
|
||||
va_start(ap, format);
|
||||
tmp = [[NSString allocWithZone: NSDefaultMallocZone()]
|
||||
tmp = [[NSStringClass allocWithZone: NSDefaultMallocZone()]
|
||||
initWithFormat: format arguments: ap];
|
||||
va_end(ap);
|
||||
[self appendString: tmp];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue