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:
richard 2001-02-02 06:14:42 +00:00
parent b4c65db38d
commit 074583906b
8 changed files with 2519 additions and 415 deletions

View file

@ -1,3 +1,14 @@
2001-02-02 Richard Frith-Macdonald <rfm@gnu.org>
Integrated patch for unicode support for ([-initWithFormat:]) by
Kai Henningsen. Modified to support efficient append with format
to a unicode string.
* configure.in: Test for data type used by GSFormat
* Headers/gnustep/base/GSFormat.h: file declaring GSFormat info.
* Source/GSFormat.m: Source for format support.
* Source/NSString.m: Use GSFormat() to implement ([-initWithFormat:])
* Source/GSString.m: use GSFormat() to implement ([-appendFormat:])
2001-01-31 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSDate.m: pass dates over DO bycopy unless explicitly byref.

View file

@ -0,0 +1,43 @@
/* GSFormat - printf-style formatting
Copyright (C) 2000 Free Software Foundation, Inc.
Written by: Kai Henningsen <kai@cats.ms>
Created: Jan 2001
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef __GSFormat_H_
#define __GSFormat_H_
#include <Foundation/NSZone.h>
@class NSDictionary;
typedef struct {
unichar *buf;
size_t len;
size_t size;
NSZone *z;
} FormatBuf_t;
void
GSFormat(FormatBuf_t *fb, const unichar *fmt, va_list ap, NSDictionary *loc);
#endif

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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)

View file

@ -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];

935
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -588,6 +588,21 @@ AC_CHECK_FUNCS(usleep)
#--------------------------------------------------------------------
AC_CHECK_FUNCS(strerror)
#--------------------------------------------------------------------
# This type needed by GSFormat
#--------------------------------------------------------------------
AC_MSG_CHECKING([whether stdint.h defines uintmax_t])
AC_TRY_COMPILE([#include <stdint.h>
f() { int i = sizeof(uintmax_t); }],
uintmax_t=1, uintmax_t=0,
uintmax_t=1)
if test $uintmax_t = 1; then
AC_MSG_RESULT([found])
AC_DEFINE(HAVE_UINTMAX_T)
else
AC_MSG_RESULT([not found])
fi
#--------------------------------------------------------------------
# This function needed by NSString for handling of %@ printf directive.
#--------------------------------------------------------------------