1995-03-12 19:54:14 +00:00
|
|
|
/* Implementation of GNUSTEP string class
|
1998-10-15 05:03:16 +00:00
|
|
|
Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
|
1995-03-12 19:54:14 +00:00
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1995-03-12 19:54:14 +00:00
|
|
|
Date: January 1995
|
1997-05-03 18:05:21 +00:00
|
|
|
|
1998-01-08 15:25:59 +00:00
|
|
|
Unicode implementation by Stevo Crvenkovski <stevo@btinternet.com>
|
1997-05-03 18:05:21 +00:00
|
|
|
Date: February 1997
|
|
|
|
|
1998-10-15 05:03:16 +00:00
|
|
|
Optimisations by Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
Date: October 1998
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1995-03-12 19:54:14 +00:00
|
|
|
|
|
|
|
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.
|
1997-05-03 18:05:21 +00:00
|
|
|
|
1995-03-12 19:54:14 +00:00
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
1997-05-03 18:05:21 +00:00
|
|
|
*/
|
1995-03-12 19:54:14 +00:00
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
/* Caveats:
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
Some implementations will need to be changed.
|
1996-09-02 13:20:20 +00:00
|
|
|
Does not support all justification directives for `%@' in format strings
|
|
|
|
on non-GNU-libc systems.
|
1995-04-03 01:35:42 +00:00
|
|
|
*/
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
/* Initial implementation of Unicode. Version 0.0.0 :)
|
1997-09-01 21:59:51 +00:00
|
|
|
Locales not yet supported.
|
1997-05-03 18:05:21 +00:00
|
|
|
Limited choice of default encodings.
|
|
|
|
*/
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
#include <config.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/preface.h>
|
|
|
|
#include <base/Coding.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
#include <Foundation/NSString.h>
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSCharacterSet.h>
|
1996-03-26 19:35:47 +00:00
|
|
|
#include <Foundation/NSException.h>
|
1996-02-22 15:18:57 +00:00
|
|
|
#include <Foundation/NSValue.h>
|
1996-10-31 17:03:44 +00:00
|
|
|
#include <Foundation/NSDictionary.h>
|
1996-11-24 21:04:24 +00:00
|
|
|
#include <Foundation/NSUserDefaults.h>
|
1998-10-15 18:46:27 +00:00
|
|
|
#include <Foundation/NSFileManager.h>
|
1998-12-18 17:05:44 +00:00
|
|
|
#include <Foundation/NSPortCoder.h>
|
|
|
|
#include <Foundation/NSPathUtilities.h>
|
1998-10-15 18:46:27 +00:00
|
|
|
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/IndexedCollection.h>
|
1997-09-01 21:59:51 +00:00
|
|
|
#include <Foundation/NSData.h>
|
1998-01-08 15:25:59 +00:00
|
|
|
#include <Foundation/NSBundle.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/IndexedCollectionPrivate.h>
|
1995-04-03 01:35:42 +00:00
|
|
|
#include <limits.h>
|
1996-07-15 18:41:44 +00:00
|
|
|
#include <string.h> // for strstr()
|
1996-10-31 17:03:44 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/behavior.h>
|
1997-05-03 18:05:21 +00:00
|
|
|
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/NSGSequence.h>
|
|
|
|
#include <base/Unicode.h>
|
|
|
|
#include <base/GetDefEncoding.h>
|
|
|
|
#include <base/NSGString.h>
|
|
|
|
#include <base/NSGCString.h>
|
1997-05-03 18:05:21 +00:00
|
|
|
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/fast.x>
|
1998-10-09 04:24:56 +00:00
|
|
|
|
|
|
|
|
1998-01-21 15:09:22 +00:00
|
|
|
// Uncomment when implemented
|
|
|
|
static NSStringEncoding _availableEncodings[] = {
|
|
|
|
NSASCIIStringEncoding,
|
|
|
|
NSNEXTSTEPStringEncoding,
|
|
|
|
// NSJapaneseEUCStringEncoding,
|
|
|
|
// NSUTF8StringEncoding,
|
|
|
|
NSISOLatin1StringEncoding,
|
|
|
|
// NSSymbolStringEncoding,
|
|
|
|
// NSNonLossyASCIIStringEncoding,
|
|
|
|
// NSShiftJISStringEncoding,
|
|
|
|
// NSISOLatin2StringEncoding,
|
|
|
|
NSUnicodeStringEncoding,
|
|
|
|
// NSWindowsCP1251StringEncoding,
|
|
|
|
// NSWindowsCP1252StringEncoding,
|
|
|
|
// NSWindowsCP1253StringEncoding,
|
|
|
|
// NSWindowsCP1254StringEncoding,
|
|
|
|
// NSWindowsCP1250StringEncoding,
|
|
|
|
// NSISO2022JPStringEncoding,
|
|
|
|
// GNUstep additions
|
|
|
|
NSCyrillicStringEncoding,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
static Class NSString_class; /* For speed */
|
1997-05-03 18:05:21 +00:00
|
|
|
|
1999-02-04 13:49:27 +00:00
|
|
|
/*
|
|
|
|
* Cache some commonly used character sets along with methods to
|
|
|
|
* check membership.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static SEL cMemberSel = @selector(characterIsMember:);
|
|
|
|
|
|
|
|
static NSCharacterSet *hexdigits = nil;
|
|
|
|
static BOOL (*hexdigitsImp)(id, SEL, unichar) = 0;
|
|
|
|
static void setupHexdigits()
|
|
|
|
{
|
|
|
|
if (hexdigits == nil)
|
|
|
|
{
|
|
|
|
hexdigits = [NSCharacterSet characterSetWithCharactersInString:
|
|
|
|
@"0123456789abcdef"];
|
|
|
|
[hexdigits retain];
|
|
|
|
hexdigitsImp =
|
|
|
|
(BOOL(*)(id,SEL,unichar)) [hexdigits methodForSelector: cMemberSel];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static NSCharacterSet *quotables = nil;
|
|
|
|
static BOOL (*quotablesImp)(id, SEL, unichar) = 0;
|
|
|
|
static void setupQuotables()
|
|
|
|
{
|
|
|
|
if (quotables == nil)
|
|
|
|
{
|
|
|
|
NSMutableCharacterSet *s;
|
|
|
|
|
|
|
|
s = (NSMutableCharacterSet*)[NSMutableCharacterSet
|
|
|
|
characterSetWithCharactersInString:
|
|
|
|
@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$./_"];
|
|
|
|
[s invert];
|
|
|
|
quotables = [s copy];
|
|
|
|
quotablesImp =
|
|
|
|
(BOOL(*)(id,SEL,unichar)) [quotables methodForSelector: cMemberSel];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static NSCharacterSet *whitespce = nil;
|
|
|
|
static BOOL (*whitespceImp)(id, SEL, unichar) = 0;
|
|
|
|
static void setupWhitespce()
|
|
|
|
{
|
|
|
|
if (whitespce == nil)
|
|
|
|
{
|
1999-02-04 15:49:30 +00:00
|
|
|
#if 0
|
1999-02-04 13:49:27 +00:00
|
|
|
whitespce = [NSCharacterSet whitespaceAndNewlineCharacterSet];
|
1999-02-04 15:49:30 +00:00
|
|
|
#else
|
|
|
|
whitespce = [NSMutableCharacterSet characterSetWithCharactersInString:
|
|
|
|
@" \t\r\n\f\b"];
|
|
|
|
#endif
|
1999-02-04 13:49:27 +00:00
|
|
|
[whitespce retain];
|
|
|
|
whitespceImp =
|
|
|
|
(BOOL(*)(id,SEL,unichar)) [whitespce methodForSelector: cMemberSel];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
static unichar pathSepChar = (unichar)'/';
|
|
|
|
static NSString *pathSepString = @"/";
|
1997-09-13 17:52:31 +00:00
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
/*
|
|
|
|
* We can't have a 'pathSeps' variable initialized in the +initialize
|
|
|
|
* method 'cos that would cause recursion.
|
|
|
|
*/
|
|
|
|
static NSCharacterSet*
|
|
|
|
pathSeps()
|
|
|
|
{
|
|
|
|
static NSCharacterSet *pathSeps = nil;
|
1997-09-13 17:52:31 +00:00
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
if (pathSeps == nil)
|
|
|
|
{
|
|
|
|
#if defined(__WIN32__) || defined(_WIN32)
|
|
|
|
pathSeps = [NSCharacterSet characterSetWithCharactersInString: @"/\\"];
|
1997-09-13 17:52:31 +00:00
|
|
|
#else
|
1999-01-20 13:28:28 +00:00
|
|
|
pathSeps = [NSCharacterSet characterSetWithCharactersInString: @"/"];
|
|
|
|
#endif
|
|
|
|
[pathSeps retain];
|
|
|
|
}
|
|
|
|
return pathSeps;
|
|
|
|
}
|
1997-09-13 17:52:31 +00:00
|
|
|
|
1995-03-12 19:54:14 +00:00
|
|
|
|
|
|
|
@implementation NSString
|
1995-04-03 01:35:42 +00:00
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
/* For unichar strings. */
|
1995-08-09 16:07:19 +00:00
|
|
|
static Class NSString_concrete_class;
|
|
|
|
static Class NSMutableString_concrete_class;
|
|
|
|
|
|
|
|
/* For CString's */
|
|
|
|
static Class NSString_c_concrete_class;
|
|
|
|
static Class NSMutableString_c_concrete_class;
|
|
|
|
|
1998-01-08 15:25:59 +00:00
|
|
|
static NSStringEncoding _DefaultStringEncoding;
|
|
|
|
|
|
|
|
|
1995-08-09 16:07:19 +00:00
|
|
|
+ (void) _setConcreteClass: (Class)c
|
|
|
|
{
|
|
|
|
NSString_concrete_class = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) _setConcreteCClass: (Class)c
|
|
|
|
{
|
|
|
|
NSString_c_concrete_class = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) _setMutableConcreteClass: (Class)c
|
|
|
|
{
|
|
|
|
NSMutableString_concrete_class = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) _setMutableConcreteCClass: (Class)c
|
|
|
|
{
|
|
|
|
NSMutableString_c_concrete_class = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (Class) _concreteClass
|
|
|
|
{
|
|
|
|
return NSString_concrete_class;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (Class) _concreteCClass
|
|
|
|
{
|
|
|
|
return NSString_c_concrete_class;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (Class) _mutableConcreteClass
|
|
|
|
{
|
|
|
|
return NSMutableString_concrete_class;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (Class) _mutableConcreteCClass
|
|
|
|
{
|
|
|
|
return NSMutableString_c_concrete_class;
|
|
|
|
}
|
|
|
|
|
1996-01-23 23:30:05 +00:00
|
|
|
#if HAVE_REGISTER_PRINTF_FUNCTION
|
1996-01-23 23:41:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <printf.h>
|
|
|
|
#include <stdarg.h>
|
1996-05-06 18:59:01 +00:00
|
|
|
|
1996-07-15 18:41:44 +00:00
|
|
|
/* <sattler@volker.cs.Uni-Magdeburg.DE>, with libc-5.3.9 thinks this
|
|
|
|
flag PRINTF_ATSIGN_VA_LIST should be 0, but for me, with libc-5.0.9,
|
1997-09-01 21:59:51 +00:00
|
|
|
it crashes. -mccallum
|
|
|
|
|
|
|
|
Apparently GNU libc 2.xx needs this to be 0 also, along with Linux
|
|
|
|
libc versions 5.2.xx and higher (including libc6, which is just GNU
|
|
|
|
libc). -chung */
|
1996-07-15 18:41:44 +00:00
|
|
|
#define PRINTF_ATSIGN_VA_LIST \
|
|
|
|
(defined(_LINUX_C_LIB_VERSION_MINOR) \
|
|
|
|
&& _LINUX_C_LIB_VERSION_MAJOR <= 5 \
|
|
|
|
&& _LINUX_C_LIB_VERSION_MINOR < 2)
|
1996-05-07 01:14:54 +00:00
|
|
|
|
|
|
|
#if ! PRINTF_ATSIGN_VA_LIST
|
1996-05-06 18:59:01 +00:00
|
|
|
static int
|
1997-09-01 21:59:51 +00:00
|
|
|
arginfo_func (const struct printf_info *info, size_t n, int *argtypes)
|
|
|
|
{
|
1996-05-06 18:59:01 +00:00
|
|
|
*argtypes = PA_POINTER;
|
|
|
|
return 1;
|
|
|
|
}
|
1996-07-15 18:41:44 +00:00
|
|
|
#endif /* !PRINTF_ATSIGN_VA_LIST */
|
1996-05-06 18:59:01 +00:00
|
|
|
|
|
|
|
static int
|
1996-01-23 23:41:02 +00:00
|
|
|
handle_printf_atsign (FILE *stream,
|
|
|
|
const struct printf_info *info,
|
1996-05-07 01:14:54 +00:00
|
|
|
#if PRINTF_ATSIGN_VA_LIST
|
|
|
|
va_list *ap_pointer)
|
1997-09-01 21:59:51 +00:00
|
|
|
#elif defined(_LINUX_C_LIB_VERSION_MAJOR) \
|
|
|
|
&& _LINUX_C_LIB_VERSION_MAJOR < 6
|
1996-05-07 01:14:54 +00:00
|
|
|
const void **const args)
|
1997-09-01 21:59:51 +00:00
|
|
|
#else /* GNU libc needs the following. */
|
|
|
|
const void *const *args)
|
1996-05-07 01:14:54 +00:00
|
|
|
#endif
|
1996-01-23 23:30:05 +00:00
|
|
|
{
|
1996-05-07 01:14:54 +00:00
|
|
|
#if ! PRINTF_ATSIGN_VA_LIST
|
1996-05-06 18:59:01 +00:00
|
|
|
const void *ptr = *args;
|
1996-05-07 01:14:54 +00:00
|
|
|
#endif
|
1996-01-23 23:30:05 +00:00
|
|
|
id string_object;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* xxx This implementation may not pay pay attention to as much
|
|
|
|
of printf_info as it should. */
|
|
|
|
|
1996-05-07 01:14:54 +00:00
|
|
|
#if PRINTF_ATSIGN_VA_LIST
|
|
|
|
string_object = va_arg (*ap_pointer, id);
|
|
|
|
#else
|
1996-07-15 18:41:44 +00:00
|
|
|
string_object = *((id*) ptr);
|
1996-05-07 01:14:54 +00:00
|
|
|
#endif
|
1996-01-23 23:30:05 +00:00
|
|
|
len = fprintf(stream, "%*s",
|
|
|
|
(info->left ? - info->width : info->width),
|
1998-09-30 07:42:38 +00:00
|
|
|
[[string_object description] cString]);
|
1996-01-23 23:30:05 +00:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_REGISTER_PRINTF_FUNCTION */
|
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
1996-11-24 17:20:45 +00:00
|
|
|
if (self == [NSString class])
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1998-01-08 15:25:59 +00:00
|
|
|
_DefaultStringEncoding = GetDefEncoding();
|
1999-01-20 13:28:28 +00:00
|
|
|
NSString_class = self;
|
1997-05-03 18:05:21 +00:00
|
|
|
NSString_concrete_class = [NSGString class];
|
1995-08-09 16:07:19 +00:00
|
|
|
NSString_c_concrete_class = [NSGCString class];
|
1997-05-03 18:05:21 +00:00
|
|
|
NSMutableString_concrete_class = [NSGMutableString class];
|
1995-08-09 16:07:19 +00:00
|
|
|
NSMutableString_c_concrete_class = [NSGMutableCString class];
|
1996-01-23 23:30:05 +00:00
|
|
|
|
|
|
|
#if HAVE_REGISTER_PRINTF_FUNCTION
|
1996-01-23 23:41:02 +00:00
|
|
|
if (register_printf_function ('@',
|
1997-09-01 21:59:51 +00:00
|
|
|
handle_printf_atsign,
|
1996-05-07 01:14:54 +00:00
|
|
|
#if PRINTF_ATSIGN_VA_LIST
|
|
|
|
0))
|
|
|
|
#else
|
1997-09-01 21:59:51 +00:00
|
|
|
arginfo_func))
|
1996-05-07 01:14:54 +00:00
|
|
|
#endif
|
1996-03-26 19:35:47 +00:00
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"register printf handling of %%@ failed"];
|
1996-01-23 23:30:05 +00:00
|
|
|
#endif /* HAVE_REGISTER_PRINTF_FUNCTION */
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-11-19 20:29:39 +00:00
|
|
|
+ allocWithZone: (NSZone*)z
|
|
|
|
{
|
1997-05-03 17:05:57 +00:00
|
|
|
if ([self class] == [NSString class])
|
|
|
|
return NSAllocateObject ([self _concreteClass], 0, z);
|
|
|
|
return [super allocWithZone:z];
|
1995-11-19 20:29:39 +00:00
|
|
|
}
|
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
// Creating Temporary Strings
|
|
|
|
|
1997-05-03 17:05:57 +00:00
|
|
|
+ (NSString*) string
|
|
|
|
{
|
|
|
|
return [[[self alloc] init] autorelease];
|
|
|
|
}
|
|
|
|
|
1997-12-08 20:04:16 +00:00
|
|
|
+ (NSString*) stringWithString: (NSString*)aString
|
|
|
|
{
|
|
|
|
return [[[self alloc] initWithString: aString] autorelease];
|
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
+ (NSString*) stringWithCharacters: (const unichar*)chars
|
|
|
|
length: (unsigned int)length
|
|
|
|
{
|
|
|
|
return [[[self alloc]
|
|
|
|
initWithCharacters:chars length:length]
|
|
|
|
autorelease];
|
|
|
|
}
|
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
+ (NSString*) stringWithCString: (const char*) byteString
|
|
|
|
{
|
1998-10-06 15:11:27 +00:00
|
|
|
return [[[NSString_c_concrete_class alloc] initWithCString:byteString]
|
1995-04-03 01:35:42 +00:00
|
|
|
autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSString*) stringWithCString: (const char*)byteString
|
|
|
|
length: (unsigned int)length
|
|
|
|
{
|
1998-10-06 15:11:27 +00:00
|
|
|
return [[[NSString_c_concrete_class alloc]
|
1995-08-09 16:07:19 +00:00
|
|
|
initWithCString:byteString length:length]
|
1995-04-03 01:35:42 +00:00
|
|
|
autorelease];
|
|
|
|
}
|
|
|
|
|
1997-03-03 20:07:35 +00:00
|
|
|
+ (NSString*) stringWithContentsOfFile:(NSString *)path
|
|
|
|
{
|
|
|
|
return [[[self alloc]
|
|
|
|
initWithContentsOfFile: path] autorelease];
|
|
|
|
}
|
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
+ (NSString*) stringWithFormat: (NSString*)format,...
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
id ret;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
1995-11-19 20:29:39 +00:00
|
|
|
ret = [[[self alloc] initWithFormat:format arguments:ap]
|
1995-04-03 01:35:42 +00:00
|
|
|
autorelease];
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSString*) stringWithFormat: (NSString*)format
|
|
|
|
arguments: (va_list)argList
|
|
|
|
{
|
1995-11-19 20:29:39 +00:00
|
|
|
return [[[self alloc]
|
1995-08-09 16:07:19 +00:00
|
|
|
initWithFormat:format arguments:argList]
|
1995-04-03 01:35:42 +00:00
|
|
|
autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
// Initializing Newly Allocated Strings
|
1995-04-03 01:35:42 +00:00
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
/* This is the designated initializer for Unicode Strings. */
|
1998-10-15 05:03:16 +00:00
|
|
|
- (id) initWithCharactersNoCopy: (unichar*)chars
|
|
|
|
length: (unsigned int)length
|
|
|
|
fromZone: (NSZone*)zone
|
|
|
|
{
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
- (id) initWithCharactersNoCopy: (unichar*)chars
|
1995-04-03 01:35:42 +00:00
|
|
|
length: (unsigned int)length
|
|
|
|
freeWhenDone: (BOOL)flag
|
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
if (flag)
|
|
|
|
return [self initWithCharactersNoCopy: chars
|
|
|
|
length: length
|
|
|
|
fromZone: NSZoneFromPointer(chars)];
|
|
|
|
else
|
|
|
|
return [self initWithCharactersNoCopy: chars
|
|
|
|
length: length
|
|
|
|
fromZone: 0];
|
1995-04-03 01:35:42 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCharacters: (const unichar*)chars
|
1998-10-15 05:03:16 +00:00
|
|
|
length: (unsigned int)length
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
NSZone *z = [self zone];
|
|
|
|
unichar *s = NSZoneMalloc(z, sizeof(unichar)*length);
|
|
|
|
|
|
|
|
if (chars)
|
|
|
|
memcpy(s, chars, sizeof(unichar)*length);
|
|
|
|
|
|
|
|
return [self initWithCharactersNoCopy:s length:length fromZone:z];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCStringNoCopy: (char*)byteString
|
|
|
|
length: (unsigned int)length
|
|
|
|
freeWhenDone: (BOOL)flag
|
|
|
|
{
|
|
|
|
if (flag)
|
|
|
|
return [self initWithCStringNoCopy: byteString
|
|
|
|
length: length
|
|
|
|
fromZone: NSZoneFromPointer(byteString)];
|
|
|
|
else
|
|
|
|
return [self initWithCStringNoCopy: byteString
|
|
|
|
length: length
|
|
|
|
fromZone: 0];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
/* This is the designated initializer for CStrings. */
|
|
|
|
- (id) initWithCStringNoCopy: (char*)byteString
|
1998-10-15 05:03:16 +00:00
|
|
|
length: (unsigned int)length
|
|
|
|
fromZone: (NSZone*)zone
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1995-08-09 16:26:44 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-03 01:35:42 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
- (id) initWithCString: (const char*)byteString length: (unsigned int)length
|
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
NSZone *z = [self zone];
|
|
|
|
char *s = NSZoneMalloc(z, length);
|
|
|
|
|
|
|
|
if (byteString)
|
|
|
|
memcpy(s, byteString, length);
|
|
|
|
return [self initWithCStringNoCopy:s length:length fromZone:z];
|
1997-05-03 18:05:21 +00:00
|
|
|
}
|
1997-01-09 16:24:07 +00:00
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
- (id) initWithCString: (const char*)byteString
|
|
|
|
{
|
|
|
|
return [self initWithCString:byteString
|
|
|
|
length:(byteString ? strlen(byteString) : 0)];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
- (id) initWithString: (NSString*)string
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
NSZone *z = [self zone];
|
|
|
|
unsigned length = [string length];
|
|
|
|
unichar *s = NSZoneMalloc(z, sizeof(unichar)*length);
|
|
|
|
|
|
|
|
[string getCharacters:s];
|
|
|
|
return [self initWithCharactersNoCopy: s
|
|
|
|
length: length
|
|
|
|
fromZone: z];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithFormat: (NSString*)format,...
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
self = [self initWithFormat:format arguments:ap];
|
|
|
|
va_end(ap);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* xxx Change this when we have non-CString classes */
|
|
|
|
- (id) initWithFormat: (NSString*)format
|
1996-07-15 18:41:44 +00:00
|
|
|
arguments: (va_list)arg_list
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
|
|
|
#if HAVE_VSPRINTF
|
1998-09-30 07:42:38 +00:00
|
|
|
const char *format_cp = [format cString];
|
1996-05-31 15:10:53 +00:00
|
|
|
int format_len = strlen (format_cp);
|
1996-07-15 18:41:44 +00:00
|
|
|
/* xxx horrible disgusting BUFFER_EXTRA arbitrary limit; fix this! */
|
1997-01-09 16:01:52 +00:00
|
|
|
#define BUFFER_EXTRA 1024*500
|
1996-07-15 18:41:44 +00:00
|
|
|
char buf[format_len + BUFFER_EXTRA];
|
|
|
|
int printed_len = 0;
|
|
|
|
|
|
|
|
#if ! HAVE_REGISTER_PRINTF_FUNCTION
|
|
|
|
/* If the available libc doesn't have `register_printf_function()', then
|
|
|
|
the `%@' printf directive isn't available with printf() and friends.
|
|
|
|
Here we make a feable attempt to handle it. */
|
|
|
|
{
|
|
|
|
/* We need a local copy since we change it. (Changing and undoing
|
|
|
|
the change doesn't work because some format strings are constant
|
|
|
|
strings, placed in a non-writable section of the executable, and
|
1996-09-02 13:20:20 +00:00
|
|
|
writing to them will cause a segfault.) */
|
1996-07-15 18:41:44 +00:00
|
|
|
char format_cp_copy[format_len+1];
|
1996-09-25 13:45:31 +00:00
|
|
|
char *atsign_pos; /* points to a location inside format_cp_copy */
|
1996-07-15 18:41:44 +00:00
|
|
|
char *format_to_go = format_cp_copy;
|
|
|
|
strcpy (format_cp_copy, format_cp);
|
|
|
|
/* Loop once for each `%@' in the format string. */
|
|
|
|
while ((atsign_pos = strstr (format_to_go, "%@")))
|
|
|
|
{
|
|
|
|
const char *cstring;
|
1997-09-01 21:59:51 +00:00
|
|
|
char *formatter_pos; // Position for formatter.
|
|
|
|
|
1996-07-15 18:41:44 +00:00
|
|
|
/* If there is a "%%@", then do the right thing: print it literally. */
|
|
|
|
if ((*(atsign_pos-1) == '%')
|
|
|
|
&& atsign_pos != format_cp_copy)
|
|
|
|
continue;
|
|
|
|
/* Temporarily terminate the string before the `%@'. */
|
|
|
|
*atsign_pos = '\0';
|
|
|
|
/* Print the part before the '%@' */
|
1996-10-31 18:27:04 +00:00
|
|
|
printed_len += VSPRINTF_LENGTH (vsprintf (buf+printed_len,
|
|
|
|
format_to_go, arg_list));
|
1997-09-01 21:59:51 +00:00
|
|
|
/* Skip arguments used in last vsprintf(). */
|
|
|
|
while ((formatter_pos = strchr(format_to_go, '%')))
|
|
|
|
{
|
|
|
|
char *spec_pos; // Position of conversion specifier.
|
|
|
|
|
|
|
|
if (*(formatter_pos+1) == '%')
|
|
|
|
{
|
|
|
|
format_to_go = formatter_pos+2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Specifiers from K&R C 2nd ed. */
|
|
|
|
spec_pos = strpbrk(formatter_pos+1, "dioxXucsfeEgGpn\0");
|
|
|
|
switch (*spec_pos)
|
|
|
|
{
|
|
|
|
case 'd': case 'i': case 'o':
|
|
|
|
case 'x': case 'X': case 'u': case 'c':
|
|
|
|
va_arg(arg_list, int);
|
|
|
|
break;
|
|
|
|
case 's':
|
1997-09-18 14:56:47 +00:00
|
|
|
if (*(spec_pos - 1) == '*')
|
|
|
|
va_arg(arg_list, int*);
|
1997-09-01 21:59:51 +00:00
|
|
|
va_arg(arg_list, char*);
|
|
|
|
break;
|
|
|
|
case 'f': case 'e': case 'E': case 'g': case 'G':
|
|
|
|
va_arg(arg_list, double);
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
va_arg(arg_list, void*);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
va_arg(arg_list, int*);
|
|
|
|
break;
|
|
|
|
case '\0':
|
|
|
|
/* Make sure loop exits on next iteration. */
|
|
|
|
spec_pos--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
format_to_go = spec_pos+1;
|
|
|
|
}
|
1996-07-15 18:41:44 +00:00
|
|
|
/* Get a C-string (char*) from the String object, and print it. */
|
1998-09-30 07:42:38 +00:00
|
|
|
cstring = [[(id) va_arg (arg_list, id) description] cString];
|
1997-11-12 15:37:27 +00:00
|
|
|
if (!cstring)
|
|
|
|
cstring = "<null string>";
|
1996-07-15 18:41:44 +00:00
|
|
|
strcat (buf+printed_len, cstring);
|
|
|
|
printed_len += strlen (cstring);
|
|
|
|
/* Skip over this `%@', and look for another one. */
|
|
|
|
format_to_go = atsign_pos + 2;
|
|
|
|
}
|
|
|
|
/* Print the rest of the string after the last `%@'. */
|
1996-10-31 18:27:04 +00:00
|
|
|
printed_len += VSPRINTF_LENGTH (vsprintf (buf+printed_len,
|
|
|
|
format_to_go, arg_list));
|
1996-07-15 18:41:44 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* The available libc has `register_printf_function()', so the `%@'
|
|
|
|
printf directive is handled by printf and friends. */
|
1996-10-31 18:27:04 +00:00
|
|
|
printed_len = VSPRINTF_LENGTH (vsprintf (buf, format_cp, arg_list));
|
1996-07-15 18:41:44 +00:00
|
|
|
#endif /* !HAVE_REGISTER_PRINTF_FUNCTION */
|
1996-05-31 15:10:53 +00:00
|
|
|
|
1996-07-15 18:41:44 +00:00
|
|
|
/* Raise an exception if we overran our buffer. */
|
1996-05-31 15:10:53 +00:00
|
|
|
NSParameterAssert (printed_len < format_len + BUFFER_EXTRA - 1);
|
1995-04-03 01:35:42 +00:00
|
|
|
return [self initWithCString:buf];
|
1996-07-15 18:41:44 +00:00
|
|
|
#else /* HAVE_VSPRINTF */
|
|
|
|
[self notImplemented: _cmd];
|
1995-04-03 01:35:42 +00:00
|
|
|
return self;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithFormat: (NSString*)format
|
|
|
|
locale: (NSDictionary*)dictionary
|
|
|
|
{
|
|
|
|
[self notImplemented:_cmd];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithFormat: (NSString*)format
|
|
|
|
locale: (NSDictionary*)dictionary
|
|
|
|
arguments: (va_list)argList
|
|
|
|
{
|
|
|
|
[self notImplemented:_cmd];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
- (id) initWithData: (NSData*)data
|
|
|
|
encoding: (NSStringEncoding)encoding
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
if ((encoding==[NSString defaultCStringEncoding])
|
|
|
|
|| (encoding==NSASCIIStringEncoding))
|
|
|
|
{
|
|
|
|
NSZone *z = fastZone(self);
|
|
|
|
int len=[data length];
|
|
|
|
char *s = NSZoneMalloc(z, len+1);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
1998-10-15 05:03:16 +00:00
|
|
|
[data getBytes:s];
|
|
|
|
return [self initWithCStringNoCopy:s length:len fromZone:z];
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
else
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
NSZone *z = fastZone(self);
|
|
|
|
int len=[data length];
|
|
|
|
unichar *u = NSZoneMalloc(z, sizeof(unichar)*(len+1));
|
|
|
|
int count;
|
|
|
|
const unsigned char *b=[data bytes];
|
|
|
|
|
1999-02-04 13:49:27 +00:00
|
|
|
if (encoding==NSUnicodeStringEncoding)
|
1998-10-15 05:03:16 +00:00
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
if ((b[0]==0xFE)&(b[1]==0xFF))
|
1998-10-15 05:03:16 +00:00
|
|
|
for(count=2;count<(len-1);count+=2)
|
|
|
|
u[count/2 - 1]=256*b[count]+b[count+1];
|
|
|
|
else
|
|
|
|
for(count=2;count<(len-1);count+=2)
|
|
|
|
u[count/2 -1]=256*b[count+1]+b[count];
|
|
|
|
count = count/2 -1;
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
else
|
1998-10-15 05:03:16 +00:00
|
|
|
count = encode_strtoustr(u,b,len,encoding);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
1998-10-15 05:03:16 +00:00
|
|
|
return [self initWithCharactersNoCopy:u length:count fromZone:z];
|
|
|
|
}
|
1997-05-03 18:05:21 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithContentsOfFile: (NSString*)path
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
|
|
|
unsigned char *buff;
|
|
|
|
NSStringEncoding enc;
|
|
|
|
id d = [NSData dataWithContentsOfFile: path];
|
|
|
|
const unsigned char *test=[d bytes];
|
|
|
|
unsigned int len = [d length];
|
1997-05-03 18:05:21 +00:00
|
|
|
|
1998-01-21 14:56:24 +00:00
|
|
|
if (d == nil) return nil;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (test && (((test[0]==0xFF) && (test[1]==0xFE)) || ((test[1]==0xFF) && (test[0]==0xFE))))
|
1998-01-08 15:25:59 +00:00
|
|
|
enc = NSUnicodeStringEncoding;
|
|
|
|
else
|
|
|
|
enc = [NSString defaultCStringEncoding];
|
|
|
|
return [self initWithData:d encoding:enc];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
1998-03-12 14:21:20 +00:00
|
|
|
self = [super init];
|
1997-12-08 20:04:16 +00:00
|
|
|
return self;
|
1997-05-03 18:05:21 +00:00
|
|
|
}
|
1995-04-03 01:35:42 +00:00
|
|
|
|
|
|
|
// Getting a String's Length
|
|
|
|
|
|
|
|
- (unsigned int) length
|
|
|
|
{
|
1997-05-03 18:05:21 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
return 0;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accessing Characters
|
|
|
|
|
|
|
|
- (unichar) characterAtIndex: (unsigned int)index
|
|
|
|
{
|
1997-05-03 18:05:21 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
return (unichar)0;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Inefficient. Should be overridden */
|
|
|
|
- (void) getCharacters: (unichar*)buffer
|
|
|
|
{
|
|
|
|
[self getCharacters:buffer range:((NSRange){0,[self length]})];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Inefficient. Should be overridden */
|
|
|
|
- (void) getCharacters: (unichar*)buffer
|
|
|
|
range: (NSRange)aRange
|
|
|
|
{
|
|
|
|
int i;
|
1996-09-02 13:38:19 +00:00
|
|
|
for (i = 0; i < aRange.length; i++)
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1996-09-02 13:38:19 +00:00
|
|
|
buffer[i] = [self characterAtIndex: aRange.location+i];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Combining Strings
|
|
|
|
|
|
|
|
- (NSString*) stringByAppendingFormat: (NSString*)format,...
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
id ret;
|
|
|
|
va_start(ap, format);
|
|
|
|
ret = [self stringByAppendingString:
|
|
|
|
[NSString stringWithFormat:format arguments:ap]];
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) stringByAppendingString: (NSString*)aString
|
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
NSZone *z = fastZone(self);
|
1997-05-03 18:05:21 +00:00
|
|
|
unsigned len = [self length];
|
1998-02-03 14:20:00 +00:00
|
|
|
unsigned otherLength = [aString length];
|
1998-10-15 05:03:16 +00:00
|
|
|
unichar *s = NSZoneMalloc(z, (len+otherLength)*sizeof(unichar));
|
1997-10-31 16:26:44 +00:00
|
|
|
NSString *tmp;
|
1998-10-15 05:03:16 +00:00
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
[self getCharacters:s];
|
|
|
|
[aString getCharacters:s+len];
|
1998-10-15 05:03:16 +00:00
|
|
|
tmp = [[[self class] allocWithZone:z] initWithCharactersNoCopy: s
|
|
|
|
length: len+otherLength fromZone: z];
|
1998-02-03 14:20:00 +00:00
|
|
|
return [tmp autorelease];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dividing Strings into Substrings
|
|
|
|
|
|
|
|
- (NSArray*) componentsSeparatedByString: (NSString*)separator
|
|
|
|
{
|
1997-09-13 17:52:31 +00:00
|
|
|
NSRange search, complete;
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange found;
|
1996-03-19 01:44:01 +00:00
|
|
|
NSMutableArray *array = [NSMutableArray array];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
|
1997-03-03 20:07:35 +00:00
|
|
|
search = NSMakeRange (0, [self length]);
|
1997-09-13 17:52:31 +00:00
|
|
|
complete = search;
|
1996-03-19 01:44:01 +00:00
|
|
|
found = [self rangeOfString: separator];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
while (found.length)
|
|
|
|
{
|
|
|
|
NSRange current;
|
1997-09-13 17:52:31 +00:00
|
|
|
|
1996-03-19 01:44:01 +00:00
|
|
|
current = NSMakeRange (search.location,
|
|
|
|
found.location - search.location);
|
|
|
|
[array addObject: [self substringFromRange: current]];
|
1997-09-13 17:52:31 +00:00
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
search = NSMakeRange (found.location + found.length,
|
1997-09-13 17:52:31 +00:00
|
|
|
complete.length - found.location - found.length);
|
1996-03-19 01:44:01 +00:00
|
|
|
found = [self rangeOfString: separator
|
|
|
|
options: 0
|
|
|
|
range: search];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
}
|
1997-03-03 20:07:35 +00:00
|
|
|
// Add the last search string range
|
|
|
|
[array addObject: [self substringFromRange: search]];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
|
|
|
|
// FIXME: Need to make mutable array into non-mutable array?
|
|
|
|
return array;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) substringFromIndex: (unsigned int)index
|
|
|
|
{
|
|
|
|
return [self substringFromRange:((NSRange){index, [self length]-index})];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) substringFromRange: (NSRange)aRange
|
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
NSZone *z;
|
1997-12-08 20:04:16 +00:00
|
|
|
unichar *buf;
|
|
|
|
id ret;
|
|
|
|
|
|
|
|
if (aRange.location > [self length])
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location."];
|
|
|
|
if (aRange.length > ([self length] - aRange.location))
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location+length."];
|
|
|
|
if (aRange.length == 0)
|
|
|
|
return @"";
|
1998-10-15 05:03:16 +00:00
|
|
|
z = fastZone(self);
|
|
|
|
buf = NSZoneMalloc(z, sizeof(unichar)*aRange.length);
|
1997-12-08 20:04:16 +00:00
|
|
|
[self getCharacters:buf range:aRange];
|
1998-02-03 14:20:00 +00:00
|
|
|
ret = [[[self class] alloc] initWithCharactersNoCopy: buf
|
|
|
|
length: aRange.length
|
1998-10-15 05:03:16 +00:00
|
|
|
fromZone: z];
|
1998-02-03 14:20:00 +00:00
|
|
|
return [ret autorelease];
|
1997-12-08 20:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) substringWithRange: (NSRange)aRange
|
|
|
|
{
|
|
|
|
return [self substringFromRange: aRange];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) substringToIndex: (unsigned int)index
|
|
|
|
{
|
1997-05-03 17:26:16 +00:00
|
|
|
return [self substringFromRange:((NSRange){0,index})];;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Finding Ranges of Characters and Substrings
|
|
|
|
|
|
|
|
- (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange all = NSMakeRange(0, [self length]);
|
|
|
|
return [self rangeOfCharacterFromSet:aSet
|
|
|
|
options:0
|
|
|
|
range:all];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet
|
|
|
|
options: (unsigned int)mask
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange all = NSMakeRange(0, [self length]);
|
|
|
|
return [self rangeOfCharacterFromSet:aSet
|
|
|
|
options:mask
|
|
|
|
range:all];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
/* xxx FIXME */
|
1995-04-03 01:35:42 +00:00
|
|
|
- (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet
|
1998-11-19 20:42:06 +00:00
|
|
|
options: (unsigned int)mask
|
|
|
|
range: (NSRange)aRange
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
int i, start, stop, step;
|
|
|
|
NSRange range;
|
1999-02-04 13:49:27 +00:00
|
|
|
unichar (*cImp)(id, SEL, unsigned);
|
|
|
|
BOOL (*mImp)(id, SEL, unichar);
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
|
1998-11-19 20:42:06 +00:00
|
|
|
i = [self length];
|
|
|
|
if (aRange.location > i)
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location."];
|
|
|
|
if (aRange.length > (i - aRange.location))
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location+length."];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
|
|
|
|
if ((mask & NSBackwardsSearch) == NSBackwardsSearch)
|
|
|
|
{
|
1998-07-15 12:48:57 +00:00
|
|
|
start = NSMaxRange(aRange)-1; stop = aRange.location-1; step = -1;
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start = aRange.location; stop = NSMaxRange(aRange); step = 1;
|
|
|
|
}
|
1999-01-20 18:26:46 +00:00
|
|
|
range.location = 0;
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
range.length = 0;
|
1999-02-04 13:49:27 +00:00
|
|
|
|
|
|
|
cImp = (unichar(*)(id,SEL,unsigned))
|
|
|
|
[self methodForSelector: @selector(characterAtIndex:)];
|
|
|
|
mImp = (BOOL(*)(id,SEL,unichar))
|
|
|
|
[aSet methodForSelector: cMemberSel];
|
|
|
|
|
|
|
|
for (i = start; i != stop; i += step)
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
unichar letter = (unichar)(*cImp)(self, @selector(characterAtIndex:), i);
|
|
|
|
if ((*mImp)(aSet, cMemberSel, letter))
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
{
|
|
|
|
range = NSMakeRange(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return range;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange) rangeOfString: (NSString*)string
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange all = NSMakeRange(0, [self length]);
|
|
|
|
return [self rangeOfString:string
|
|
|
|
options:0
|
|
|
|
range:all];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange) rangeOfString: (NSString*)string
|
|
|
|
options: (unsigned int)mask
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange all = NSMakeRange(0, [self length]);
|
|
|
|
return [self rangeOfString:string
|
|
|
|
options:mask
|
|
|
|
range:all];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
- (NSRange) _searchForwardCaseInsensitiveLiteral:(NSString *) aString
|
1996-09-02 13:38:19 +00:00
|
|
|
options:(unsigned int) mask
|
|
|
|
range:(NSRange) aRange
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1997-05-03 18:05:21 +00:00
|
|
|
unsigned int myIndex, myEndIndex;
|
1996-09-02 13:38:19 +00:00
|
|
|
unsigned int strLength;
|
|
|
|
unichar strFirstCharacter;
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
strLength = [aString length];
|
|
|
|
|
|
|
|
myIndex = aRange.location;
|
|
|
|
myEndIndex = aRange.location + aRange.length - strLength;
|
|
|
|
|
|
|
|
if (mask & NSAnchoredSearch)
|
|
|
|
myEndIndex = myIndex;
|
|
|
|
|
|
|
|
strFirstCharacter = [aString characterAtIndex:0];
|
|
|
|
|
1997-05-03 20:39:07 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
unsigned int i = 1;
|
|
|
|
unichar myCharacter = [self characterAtIndex:myIndex];
|
|
|
|
unichar strCharacter = strFirstCharacter;
|
1997-05-03 18:05:21 +00:00
|
|
|
|
1997-05-03 20:39:07 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if ((myCharacter != strCharacter) &&
|
|
|
|
((uni_tolower (myCharacter) != uni_tolower (strCharacter))))
|
|
|
|
break;
|
|
|
|
if (i == strLength)
|
|
|
|
return (NSRange){myIndex, strLength};
|
|
|
|
myCharacter = [self characterAtIndex:myIndex + i];
|
|
|
|
strCharacter = [aString characterAtIndex:i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (myIndex == myEndIndex)
|
|
|
|
break;
|
|
|
|
myIndex ++;
|
|
|
|
}
|
1997-05-03 18:05:21 +00:00
|
|
|
return (NSRange){0, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange) _searchBackwardCaseInsensitiveLiteral:(NSString *) aString
|
|
|
|
options:(unsigned int) mask
|
|
|
|
range:(NSRange) aRange
|
|
|
|
{
|
|
|
|
unsigned int myIndex, myEndIndex;
|
|
|
|
unsigned int strLength;
|
|
|
|
unichar strFirstCharacter;
|
1996-09-02 13:38:19 +00:00
|
|
|
|
|
|
|
strLength = [aString length];
|
1995-04-03 01:35:42 +00:00
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
myIndex = aRange.location + aRange.length - strLength;
|
|
|
|
myEndIndex = aRange.location;
|
|
|
|
|
|
|
|
|
1996-09-02 13:38:19 +00:00
|
|
|
if (mask & NSAnchoredSearch)
|
|
|
|
myEndIndex = myIndex;
|
|
|
|
|
|
|
|
strFirstCharacter = [aString characterAtIndex:0];
|
1997-05-03 18:05:21 +00:00
|
|
|
|
1996-09-02 13:38:19 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
unsigned int i = 1;
|
|
|
|
unichar myCharacter = [self characterAtIndex:myIndex];
|
|
|
|
unichar strCharacter = strFirstCharacter;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if ((myCharacter != strCharacter) &&
|
1997-05-03 18:05:21 +00:00
|
|
|
((uni_tolower (myCharacter) != uni_tolower (strCharacter))))
|
1996-09-02 13:38:19 +00:00
|
|
|
break;
|
|
|
|
if (i == strLength)
|
|
|
|
return (NSRange){myIndex, strLength};
|
|
|
|
myCharacter = [self characterAtIndex:myIndex + i];
|
|
|
|
strCharacter = [aString characterAtIndex:i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (myIndex == myEndIndex)
|
|
|
|
break;
|
1997-05-03 18:05:21 +00:00
|
|
|
myIndex --;
|
1996-09-02 13:38:19 +00:00
|
|
|
}
|
1997-05-03 18:05:21 +00:00
|
|
|
return (NSRange){0, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange) _searchForwardLiteral:(NSString *) aString
|
|
|
|
options:(unsigned int) mask
|
|
|
|
range:(NSRange) aRange
|
|
|
|
{
|
|
|
|
unsigned int myIndex, myEndIndex;
|
|
|
|
unsigned int strLength;
|
|
|
|
unichar strFirstCharacter;
|
|
|
|
|
|
|
|
strLength = [aString length];
|
|
|
|
|
|
|
|
myIndex = aRange.location;
|
|
|
|
myEndIndex = aRange.location + aRange.length - strLength;
|
|
|
|
|
|
|
|
if (mask & NSAnchoredSearch)
|
|
|
|
myEndIndex = myIndex;
|
|
|
|
|
|
|
|
strFirstCharacter = [aString characterAtIndex:0];
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
unsigned int i = 1;
|
|
|
|
unichar myCharacter = [self characterAtIndex:myIndex];
|
|
|
|
unichar strCharacter = strFirstCharacter;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (myCharacter != strCharacter)
|
|
|
|
break;
|
|
|
|
if (i == strLength)
|
|
|
|
return (NSRange){myIndex, strLength};
|
|
|
|
myCharacter = [self characterAtIndex:myIndex + i];
|
|
|
|
strCharacter = [aString characterAtIndex:i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (myIndex == myEndIndex)
|
|
|
|
break;
|
|
|
|
myIndex ++;
|
|
|
|
}
|
|
|
|
return (NSRange){0, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange) _searchBackwardLiteral:(NSString *) aString
|
|
|
|
options:(unsigned int) mask
|
|
|
|
range:(NSRange) aRange
|
|
|
|
{
|
|
|
|
unsigned int myIndex, myEndIndex;
|
|
|
|
unsigned int strLength;
|
|
|
|
unichar strFirstCharacter;
|
|
|
|
|
|
|
|
strLength = [aString length];
|
|
|
|
|
|
|
|
myIndex = aRange.location + aRange.length - strLength;
|
|
|
|
myEndIndex = aRange.location;
|
|
|
|
|
|
|
|
|
|
|
|
if (mask & NSAnchoredSearch)
|
|
|
|
myEndIndex = myIndex;
|
|
|
|
|
|
|
|
strFirstCharacter = [aString characterAtIndex:0];
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
unsigned int i = 1;
|
|
|
|
unichar myCharacter = [self characterAtIndex:myIndex];
|
|
|
|
unichar strCharacter = strFirstCharacter;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (myCharacter != strCharacter)
|
|
|
|
break;
|
|
|
|
if (i == strLength)
|
|
|
|
return (NSRange){myIndex, strLength};
|
|
|
|
myCharacter = [self characterAtIndex:myIndex + i];
|
|
|
|
strCharacter = [aString characterAtIndex:i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (myIndex == myEndIndex)
|
|
|
|
break;
|
|
|
|
myIndex --;
|
|
|
|
}
|
|
|
|
return (NSRange){0, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSRange) _searchForwardCaseInsensitive:(NSString *) aString
|
|
|
|
options:(unsigned int) mask
|
|
|
|
range:(NSRange) aRange
|
|
|
|
{
|
|
|
|
unsigned int myIndex, myEndIndex;
|
|
|
|
unsigned int strLength, strBaseLength;
|
|
|
|
id strFirstCharacterSeq;
|
|
|
|
|
|
|
|
strLength = [aString length];
|
|
|
|
strBaseLength = [aString _baseLength];
|
|
|
|
|
|
|
|
myIndex = aRange.location;
|
|
|
|
myEndIndex = aRange.location + aRange.length - strBaseLength;
|
|
|
|
|
|
|
|
if (mask & NSAnchoredSearch)
|
|
|
|
myEndIndex = myIndex;
|
|
|
|
|
|
|
|
strFirstCharacterSeq = [NSGSequence sequenceWithString: aString
|
|
|
|
range: [aString rangeOfComposedCharacterSequenceAtIndex: 0]];
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
NSRange myRange;
|
|
|
|
NSRange mainRange;
|
|
|
|
NSRange strRange;
|
|
|
|
unsigned int myCount = 1;
|
|
|
|
unsigned int strCount = 1;
|
|
|
|
id myCharacter = [NSGSequence sequenceWithString: self
|
|
|
|
range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex]];
|
|
|
|
id strCharacter = strFirstCharacterSeq;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (![[myCharacter normalize] isEqual: [strCharacter normalize]]
|
|
|
|
&& ![[[myCharacter lowercase] normalize] isEqual: [[strCharacter lowercase] normalize]])
|
|
|
|
|
|
|
|
break;
|
|
|
|
if (strCount >= strLength)
|
|
|
|
return (NSRange){myIndex, myCount};
|
|
|
|
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount];
|
|
|
|
myCharacter = [NSGSequence sequenceWithString: self range: myRange];
|
|
|
|
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strCount];
|
|
|
|
strCharacter = [NSGSequence sequenceWithString: aString range: strRange];
|
|
|
|
myCount += myRange.length;
|
|
|
|
strCount += strRange.length;
|
|
|
|
} /* for */
|
|
|
|
if (myIndex >= myEndIndex)
|
|
|
|
break;
|
|
|
|
mainRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex];
|
|
|
|
myIndex += mainRange.length;
|
|
|
|
} /* for */
|
|
|
|
return (NSRange){0, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange) _searchBackwardCaseInsensitive:(NSString *) aString
|
|
|
|
options:(unsigned int) mask
|
|
|
|
range:(NSRange) aRange
|
|
|
|
{
|
|
|
|
unsigned int myIndex, myEndIndex;
|
|
|
|
unsigned int strLength, strBaseLength;
|
|
|
|
id strFirstCharacterSeq;
|
|
|
|
|
|
|
|
strLength = [aString length];
|
|
|
|
strBaseLength = [aString _baseLength];
|
|
|
|
|
|
|
|
myIndex = aRange.location + aRange.length - strBaseLength;
|
|
|
|
myEndIndex = aRange.location;
|
|
|
|
|
|
|
|
if (mask & NSAnchoredSearch)
|
|
|
|
myEndIndex = myIndex;
|
|
|
|
|
|
|
|
strFirstCharacterSeq = [NSGSequence sequenceWithString: aString
|
|
|
|
range: [aString rangeOfComposedCharacterSequenceAtIndex: 0]];
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
NSRange myRange;
|
|
|
|
NSRange strRange;
|
|
|
|
unsigned int myCount = 1;
|
|
|
|
unsigned int strCount = 1;
|
|
|
|
id myCharacter = [NSGSequence sequenceWithString: self
|
|
|
|
range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex]];
|
|
|
|
id strCharacter = strFirstCharacterSeq;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (![[myCharacter normalize] isEqual: [strCharacter normalize]]
|
|
|
|
&& ![[[myCharacter lowercase] normalize] isEqual: [[strCharacter lowercase] normalize]])
|
|
|
|
|
|
|
|
break;
|
|
|
|
if (strCount >= strLength)
|
|
|
|
return (NSRange){myIndex, myCount};
|
|
|
|
myCharacter = [NSGSequence sequenceWithString: self range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount]];
|
|
|
|
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount];
|
|
|
|
strCharacter = [NSGSequence sequenceWithString: aString range: [aString rangeOfComposedCharacterSequenceAtIndex: strCount]];
|
|
|
|
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strCount];
|
|
|
|
myCount += myRange.length;
|
|
|
|
strCount += strRange.length;
|
|
|
|
} /* for */
|
|
|
|
if (myIndex <= myEndIndex)
|
|
|
|
break;
|
|
|
|
myIndex--;
|
1999-02-04 13:49:27 +00:00
|
|
|
while (uni_isnonsp([self characterAtIndex: myIndex])&&(myIndex>0))
|
1997-05-03 18:05:21 +00:00
|
|
|
myIndex--;
|
|
|
|
} /* for */
|
|
|
|
return (NSRange){0, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSRange) _searchForward:(NSString *) aString
|
|
|
|
options:(unsigned int) mask
|
|
|
|
range:(NSRange) aRange
|
|
|
|
{
|
|
|
|
unsigned int myIndex, myEndIndex;
|
|
|
|
unsigned int strLength, strBaseLength;
|
|
|
|
id strFirstCharacterSeq;
|
|
|
|
|
|
|
|
strLength = [aString length];
|
|
|
|
strBaseLength = [aString _baseLength];
|
|
|
|
|
|
|
|
myIndex = aRange.location;
|
|
|
|
myEndIndex = aRange.location + aRange.length - strBaseLength;
|
|
|
|
|
|
|
|
if (mask & NSAnchoredSearch)
|
|
|
|
myEndIndex = myIndex;
|
|
|
|
|
|
|
|
strFirstCharacterSeq = [NSGSequence sequenceWithString: aString
|
|
|
|
range: [aString rangeOfComposedCharacterSequenceAtIndex: 0]];
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
NSRange myRange;
|
|
|
|
NSRange strRange;
|
|
|
|
NSRange mainRange;
|
|
|
|
unsigned int myCount = 1;
|
|
|
|
unsigned int strCount = 1;
|
|
|
|
id myCharacter = [NSGSequence sequenceWithString: self
|
|
|
|
range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex]];
|
|
|
|
id strCharacter = strFirstCharacterSeq;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (![[myCharacter normalize] isEqual: [strCharacter normalize]])
|
|
|
|
break;
|
|
|
|
if (strCount >= strLength)
|
|
|
|
return (NSRange){myIndex, myCount};
|
|
|
|
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount];
|
|
|
|
myCharacter = [NSGSequence sequenceWithString: self range: myRange];
|
|
|
|
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strCount];
|
|
|
|
strCharacter = [NSGSequence sequenceWithString: aString range: strRange];
|
|
|
|
myCount += myRange.length;
|
|
|
|
strCount += strRange.length;
|
|
|
|
} /* for */
|
|
|
|
if (myIndex >= myEndIndex)
|
|
|
|
break;
|
|
|
|
mainRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex];
|
|
|
|
myIndex += mainRange.length;
|
|
|
|
} /* for */
|
|
|
|
return (NSRange){0, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSRange) _searchBackward:(NSString *) aString
|
|
|
|
options:(unsigned int) mask
|
|
|
|
range:(NSRange) aRange
|
|
|
|
{
|
|
|
|
unsigned int myIndex, myEndIndex;
|
|
|
|
unsigned int strLength, strBaseLength;
|
|
|
|
id strFirstCharacterSeq;
|
|
|
|
|
|
|
|
strLength = [aString length];
|
|
|
|
strBaseLength = [aString _baseLength];
|
|
|
|
|
|
|
|
myIndex = aRange.location + aRange.length - strBaseLength;
|
|
|
|
myEndIndex = aRange.location;
|
|
|
|
|
|
|
|
if (mask & NSAnchoredSearch)
|
|
|
|
myEndIndex = myIndex;
|
|
|
|
|
|
|
|
strFirstCharacterSeq = [NSGSequence sequenceWithString: aString
|
|
|
|
range: [aString rangeOfComposedCharacterSequenceAtIndex: 0]];
|
|
|
|
|
1996-09-02 13:38:19 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
1997-05-03 18:05:21 +00:00
|
|
|
NSRange myRange;
|
|
|
|
NSRange strRange;
|
|
|
|
unsigned int myCount = 1;
|
|
|
|
unsigned int strCount = 1;
|
|
|
|
id myCharacter = [NSGSequence sequenceWithString: self
|
|
|
|
range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex]];
|
|
|
|
id strCharacter = strFirstCharacterSeq;
|
1996-09-02 13:38:19 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
1997-05-03 18:05:21 +00:00
|
|
|
if (![[myCharacter normalize] isEqual: [strCharacter normalize]])
|
|
|
|
|
1996-09-02 13:38:19 +00:00
|
|
|
break;
|
1997-05-03 18:05:21 +00:00
|
|
|
if (strCount >= strLength)
|
|
|
|
return (NSRange){myIndex, myCount};
|
|
|
|
myCharacter = [NSGSequence sequenceWithString: self range: [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount]];
|
|
|
|
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex + myCount];
|
|
|
|
strCharacter = [NSGSequence sequenceWithString: aString range: [aString rangeOfComposedCharacterSequenceAtIndex: strCount]];
|
|
|
|
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strCount];
|
|
|
|
myCount += myRange.length;
|
|
|
|
strCount += strRange.length;
|
|
|
|
} /* for */
|
|
|
|
if (myIndex <= myEndIndex)
|
1996-09-02 13:38:19 +00:00
|
|
|
break;
|
1997-05-03 18:05:21 +00:00
|
|
|
myIndex--;
|
1999-02-04 13:49:27 +00:00
|
|
|
while (uni_isnonsp([self characterAtIndex: myIndex])&&(myIndex>0))
|
1997-05-03 18:05:21 +00:00
|
|
|
myIndex--;
|
|
|
|
} /* for */
|
|
|
|
return (NSRange){0, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange) rangeOfString:(NSString *) aString
|
|
|
|
options:(unsigned int) mask
|
|
|
|
range:(NSRange) aRange
|
|
|
|
{
|
|
|
|
|
|
|
|
#define FCLS 3
|
|
|
|
#define BCLS 7
|
|
|
|
#define FLS 2
|
|
|
|
#define BLS 6
|
|
|
|
#define FCS 1
|
|
|
|
#define BCS 5
|
|
|
|
#define FS 0
|
|
|
|
#define BS 4
|
|
|
|
#define FCLAS 11
|
|
|
|
#define BCLAS 15
|
|
|
|
#define FLAS 10
|
|
|
|
#define BLAS 14
|
|
|
|
#define FCAS 9
|
|
|
|
#define BCAS 13
|
|
|
|
#define FAS 8
|
|
|
|
#define BAS 12
|
|
|
|
|
|
|
|
unsigned int myLength, strLength;
|
|
|
|
|
|
|
|
/* Check that the search range is reasonable */
|
|
|
|
myLength = [self length];
|
|
|
|
if (aRange.location > myLength)
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location."];
|
|
|
|
if (aRange.length > (myLength - aRange.location))
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location+length."];
|
|
|
|
|
|
|
|
|
|
|
|
/* Ensure the string can be found */
|
|
|
|
strLength = [aString length];
|
1997-09-01 21:59:51 +00:00
|
|
|
if (strLength > aRange.length || strLength == 0)
|
1997-05-03 18:05:21 +00:00
|
|
|
return (NSRange){0, 0};
|
|
|
|
|
|
|
|
switch (mask)
|
|
|
|
{
|
|
|
|
case FCLS :
|
|
|
|
case FCLAS :
|
|
|
|
return [self _searchForwardCaseInsensitiveLiteral: aString
|
|
|
|
options: mask
|
|
|
|
range: aRange];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BCLS :
|
|
|
|
case BCLAS :
|
|
|
|
return [self _searchBackwardCaseInsensitiveLiteral: aString
|
|
|
|
options: mask
|
|
|
|
range: aRange];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FLS :
|
|
|
|
case FLAS :
|
|
|
|
return [self _searchForwardLiteral: aString
|
|
|
|
options: mask
|
|
|
|
range: aRange];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLS :
|
|
|
|
case BLAS :
|
|
|
|
return [self _searchBackwardLiteral: aString
|
|
|
|
options: mask
|
|
|
|
range: aRange];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FCS :
|
|
|
|
case FCAS :
|
|
|
|
return [self _searchForwardCaseInsensitive: aString
|
|
|
|
options: mask
|
|
|
|
range: aRange];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BCS :
|
|
|
|
case BCAS :
|
|
|
|
return [self _searchBackwardCaseInsensitive: aString
|
|
|
|
options: mask
|
|
|
|
range: aRange];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BS :
|
|
|
|
case BAS :
|
|
|
|
return [self _searchBackward: aString
|
|
|
|
options: mask
|
|
|
|
range: aRange];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FS :
|
|
|
|
case FAS :
|
|
|
|
default :
|
|
|
|
return [self _searchForward: aString
|
|
|
|
options: mask
|
|
|
|
range: aRange];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (NSRange){0, 0};
|
1996-09-02 13:38:19 +00:00
|
|
|
}
|
1995-04-03 01:35:42 +00:00
|
|
|
|
|
|
|
// Determining Composed Character Sequences
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
- (NSRange) rangeOfComposedCharacterSequenceAtIndex: (unsigned int)anIndex
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1997-05-03 18:05:21 +00:00
|
|
|
unsigned int start, end;
|
|
|
|
|
|
|
|
start=anIndex;
|
1999-02-04 13:49:27 +00:00
|
|
|
while (uni_isnonsp([self characterAtIndex: start]) && start > 0)
|
1999-01-11 17:28:51 +00:00
|
|
|
start--;
|
1997-05-03 18:05:21 +00:00
|
|
|
end=start+1;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (end < [self length])
|
|
|
|
while ((end < [self length]) && (uni_isnonsp([self characterAtIndex: end])) )
|
1997-05-03 18:05:21 +00:00
|
|
|
end++;
|
|
|
|
return NSMakeRange(start, end-start);
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
// Identifying and Comparing Strings
|
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
- (NSComparisonResult) compare: (NSString*)aString
|
|
|
|
{
|
|
|
|
return [self compare:aString options:0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSComparisonResult) compare: (NSString*)aString
|
|
|
|
options: (unsigned int)mask
|
|
|
|
{
|
|
|
|
return [self compare:aString options:mask
|
1998-02-03 14:20:00 +00:00
|
|
|
range:((NSRange){0, [self length]})];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
// xxx Should implement full POSIX.2 collate
|
1995-04-03 01:35:42 +00:00
|
|
|
- (NSComparisonResult) compare: (NSString*)aString
|
|
|
|
options: (unsigned int)mask
|
|
|
|
range: (NSRange)aRange
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
if (aRange.location > [self length])
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location."];
|
|
|
|
if (aRange.length > ([self length] - aRange.location))
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location+length."];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
1998-12-26 08:44:49 +00:00
|
|
|
if (aRange.length == 0)
|
|
|
|
return NSOrderedSame;
|
1999-02-04 13:49:27 +00:00
|
|
|
if ((([self length] - aRange.location == 0) && (![aString length])))
|
1997-09-01 21:59:51 +00:00
|
|
|
return NSOrderedSame;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (![self length])
|
1997-09-01 21:59:51 +00:00
|
|
|
return NSOrderedAscending;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (![aString length])
|
1997-09-01 21:59:51 +00:00
|
|
|
return NSOrderedDescending;
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
if (mask & NSLiteralSearch)
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
int i;
|
|
|
|
int s1len = aRange.length;
|
|
|
|
int s2len = [aString length];
|
|
|
|
int end;
|
|
|
|
unichar s1[s1len+1];
|
|
|
|
unichar s2[s2len+1];
|
|
|
|
|
|
|
|
[self getCharacters:s1 range: aRange];
|
|
|
|
s1[s1len] = (unichar)0;
|
1997-05-03 18:05:21 +00:00
|
|
|
[aString getCharacters:s2];
|
1998-02-03 14:20:00 +00:00
|
|
|
s2[s2len] = (unichar)0;
|
|
|
|
end = s1len+1;
|
1998-03-12 14:21:20 +00:00
|
|
|
if (s2len < s1len)
|
1998-02-03 14:20:00 +00:00
|
|
|
end = s2len+1;
|
1995-05-05 18:29:12 +00:00
|
|
|
|
|
|
|
if (mask & NSCaseInsensitiveSearch)
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
for (i = 0; i < end; i++)
|
1995-05-05 18:29:12 +00:00
|
|
|
{
|
1997-05-03 18:05:21 +00:00
|
|
|
int c1 = uni_tolower(s1[i]);
|
|
|
|
int c2 = uni_tolower(s2[i]);
|
1995-05-05 18:29:12 +00:00
|
|
|
if (c1 < c2) return NSOrderedAscending;
|
|
|
|
if (c1 > c2) return NSOrderedDescending;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
for (i = 0; i < end; i++)
|
1995-05-05 18:29:12 +00:00
|
|
|
{
|
|
|
|
if (s1[i] < s2[i]) return NSOrderedAscending;
|
|
|
|
if (s1[i] > s2[i]) return NSOrderedDescending;
|
|
|
|
}
|
|
|
|
}
|
1998-03-12 14:21:20 +00:00
|
|
|
if (s1len > s2len)
|
|
|
|
return NSOrderedDescending;
|
|
|
|
else if (s1len < s2len)
|
|
|
|
return NSOrderedAscending;
|
|
|
|
else
|
|
|
|
return NSOrderedSame;
|
1997-05-03 18:05:21 +00:00
|
|
|
} /* if NSLiteralSearch */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int start, end, myCount, strCount;
|
|
|
|
NSRange myRange, strRange;
|
|
|
|
id mySeq, strSeq;
|
|
|
|
NSComparisonResult result;
|
|
|
|
|
|
|
|
start = aRange.location;
|
|
|
|
end = aRange.location + aRange.length;
|
|
|
|
myCount = start;
|
|
|
|
strCount = start;
|
1999-02-04 13:49:27 +00:00
|
|
|
while (myCount < end)
|
1997-05-03 18:05:21 +00:00
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
if (strCount>=[aString length])
|
1997-09-01 21:59:51 +00:00
|
|
|
return NSOrderedDescending;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (myCount>=[self length])
|
1998-03-12 14:21:20 +00:00
|
|
|
return NSOrderedAscending;
|
1997-05-03 18:05:21 +00:00
|
|
|
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myCount];
|
|
|
|
myCount += myRange.length;
|
|
|
|
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strCount];
|
|
|
|
strCount += strRange.length;
|
|
|
|
mySeq = [NSGSequence sequenceWithString: self range: myRange];
|
|
|
|
strSeq = [NSGSequence sequenceWithString: aString range: strRange];
|
|
|
|
if (mask & NSCaseInsensitiveSearch)
|
|
|
|
result = [[mySeq lowercase] compare: [strSeq lowercase]];
|
|
|
|
else
|
|
|
|
result = [mySeq compare: strSeq];
|
1999-02-04 13:49:27 +00:00
|
|
|
if (result != NSOrderedSame)
|
1997-05-03 18:05:21 +00:00
|
|
|
return result;
|
|
|
|
} /* while */
|
1999-02-04 13:49:27 +00:00
|
|
|
if (strCount<[aString length])
|
1998-03-12 14:21:20 +00:00
|
|
|
return NSOrderedAscending;
|
1997-05-03 18:05:21 +00:00
|
|
|
return NSOrderedSame;
|
|
|
|
} /* else */
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasPrefix: (NSString*)aString
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange range;
|
|
|
|
range = [self rangeOfString:aString];
|
1997-01-06 22:36:21 +00:00
|
|
|
return ((range.location == 0) && (range.length != 0)) ? YES : NO;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasSuffix: (NSString*)aString
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange range;
|
|
|
|
range = [self rangeOfString:aString options:NSBackwardsSearch];
|
1998-08-13 10:01:43 +00:00
|
|
|
return (range.length > 0 && range.location == ([self length] - [aString length])) ? YES : NO;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
- (BOOL) isEqual: (id)anObject
|
|
|
|
{
|
1998-10-09 04:24:56 +00:00
|
|
|
if (anObject == self) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
if (anObject != nil) {
|
|
|
|
Class c = fastClassOfInstance(anObject);
|
|
|
|
|
|
|
|
if (c != nil) {
|
1999-01-20 13:28:28 +00:00
|
|
|
if (fastClassIsKindOfClass(c, NSString_class)) {
|
1998-10-09 04:24:56 +00:00
|
|
|
return [self isEqualToString: anObject];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NO;
|
1997-05-03 18:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isEqualToString: (NSString*)aString
|
|
|
|
{
|
1997-09-01 21:59:51 +00:00
|
|
|
id mySeq, strSeq;
|
|
|
|
NSRange myRange, strRange;
|
1998-08-03 15:31:33 +00:00
|
|
|
unsigned int myLength;
|
|
|
|
unsigned int strLength;
|
1997-09-01 21:59:51 +00:00
|
|
|
unsigned int myIndex = 0;
|
|
|
|
unsigned int strIndex = 0;
|
|
|
|
|
1998-08-03 15:31:33 +00:00
|
|
|
if ([self hash] != [aString hash])
|
|
|
|
return NO;
|
|
|
|
myLength = [self length];
|
|
|
|
strLength = [aString length];
|
1999-02-04 13:49:27 +00:00
|
|
|
if ((!myLength) && (!strLength))
|
1997-09-01 21:59:51 +00:00
|
|
|
return YES;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (!myLength)
|
1997-09-01 21:59:51 +00:00
|
|
|
return NO;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (!strLength)
|
1997-09-01 21:59:51 +00:00
|
|
|
return NO;
|
|
|
|
|
1999-02-04 13:49:27 +00:00
|
|
|
while ((myIndex < myLength) && (strIndex < strLength))
|
|
|
|
if ([self characterAtIndex: myIndex] ==
|
1997-09-01 21:59:51 +00:00
|
|
|
[aString characterAtIndex: strIndex])
|
|
|
|
{
|
|
|
|
myIndex++;
|
|
|
|
strIndex++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex];
|
|
|
|
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strIndex];
|
1999-02-04 13:49:27 +00:00
|
|
|
if ((myRange.length < 2) || (strRange.length < 2))
|
1997-09-01 21:59:51 +00:00
|
|
|
return NO;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mySeq = [NSGSequence sequenceWithString: self range: myRange];
|
|
|
|
strSeq = [NSGSequence sequenceWithString: aString range: strRange];
|
1999-02-04 13:49:27 +00:00
|
|
|
if ([mySeq isEqual: strSeq])
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
|
|
|
myIndex += myRange.length;
|
|
|
|
strIndex += strRange.length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
1999-02-04 13:49:27 +00:00
|
|
|
if ((myIndex == myLength) && (strIndex == strLength))
|
1997-09-01 21:59:51 +00:00
|
|
|
return YES;
|
|
|
|
else
|
|
|
|
return NO;
|
1997-05-03 18:05:21 +00:00
|
|
|
}
|
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
- (unsigned int) hash
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1998-01-08 15:25:59 +00:00
|
|
|
#define MAXDEC 18
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
unsigned ret = 0;
|
|
|
|
unsigned ctr = 0;
|
|
|
|
unsigned char_count = 0;
|
1998-01-08 15:25:59 +00:00
|
|
|
unichar *source,*p;
|
|
|
|
|
|
|
|
unichar *target;
|
|
|
|
unichar *spoint;
|
|
|
|
unichar *tpoint;
|
|
|
|
unichar *dpoint;
|
|
|
|
BOOL notdone;
|
|
|
|
|
|
|
|
unichar *first,*second,tmp;
|
|
|
|
int count,len2;
|
|
|
|
|
|
|
|
int len = [self length];
|
|
|
|
|
|
|
|
if (len)
|
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
if (len > NSHashStringLength)
|
1998-01-08 15:25:59 +00:00
|
|
|
len = NSHashStringLength;
|
1998-08-03 15:31:33 +00:00
|
|
|
source = alloca(sizeof(unichar)*(len*MAXDEC+1));
|
1998-01-08 15:25:59 +00:00
|
|
|
[self getCharacters: source range:NSMakeRange(0,len)];
|
|
|
|
source[len]=(unichar)0;
|
|
|
|
|
|
|
|
// decompose
|
1998-08-03 15:31:33 +00:00
|
|
|
target = alloca(sizeof(unichar)*(len*MAXDEC+1));
|
1998-01-08 15:25:59 +00:00
|
|
|
spoint = source;
|
|
|
|
tpoint = target;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
notdone=NO;
|
|
|
|
do
|
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
if (!(dpoint=uni_is_decomp(*spoint)))
|
1998-01-08 15:25:59 +00:00
|
|
|
*tpoint++ = *spoint;
|
|
|
|
else
|
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
while (*dpoint)
|
1998-01-08 15:25:59 +00:00
|
|
|
*tpoint++=*dpoint++;
|
|
|
|
notdone=YES;
|
|
|
|
}
|
1999-02-04 13:49:27 +00:00
|
|
|
} while (*spoint++);
|
1998-01-08 15:25:59 +00:00
|
|
|
*tpoint=(unichar)0;
|
|
|
|
memcpy(source, target,2*(len*MAXDEC+1));
|
|
|
|
tpoint = target;
|
|
|
|
spoint = source;
|
1999-02-04 13:49:27 +00:00
|
|
|
} while (notdone);
|
1998-01-08 15:25:59 +00:00
|
|
|
|
|
|
|
// order
|
|
|
|
|
|
|
|
len2 = uslen(source);
|
1999-02-04 13:49:27 +00:00
|
|
|
if (len2>1)
|
1998-01-08 15:25:59 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
notdone=NO;
|
|
|
|
first=source;
|
|
|
|
second=first+1;
|
|
|
|
for(count=1;count<len2;count++)
|
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
if (uni_cop(*second))
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
if (uni_cop(*first)>uni_cop(*second))
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
|
|
|
tmp= *first;
|
|
|
|
*first= *second;
|
|
|
|
*second=tmp;
|
|
|
|
notdone=YES;
|
|
|
|
}
|
1999-02-04 13:49:27 +00:00
|
|
|
if (uni_cop(*first)==uni_cop(*second))
|
|
|
|
if (*first>*second)
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
|
|
|
tmp= *first;
|
|
|
|
*first= *second;
|
|
|
|
*second=tmp;
|
|
|
|
notdone=YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
first++;
|
|
|
|
second++;
|
|
|
|
}
|
1999-02-04 13:49:27 +00:00
|
|
|
} while (notdone);
|
1998-01-08 15:25:59 +00:00
|
|
|
|
|
|
|
p = source;
|
1998-10-06 15:11:27 +00:00
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
while (*p && char_count++ < NSHashStringLength)
|
|
|
|
{
|
1998-10-06 15:11:27 +00:00
|
|
|
#if 1
|
|
|
|
ret = (ret << 5) + ret + *p++;
|
|
|
|
#else
|
|
|
|
#if 1
|
|
|
|
ret = (ret << 4) + *p++;
|
|
|
|
ctr = ret & 0xf0000000L;
|
|
|
|
if (ctr != 0)
|
|
|
|
ret ^= ctr ^ (ctr >> 24);
|
|
|
|
#else
|
1997-09-01 21:59:51 +00:00
|
|
|
ret ^= *p++ << ctr;
|
1998-10-01 15:37:14 +00:00
|
|
|
ctr = (ctr + 4) % 20;
|
1998-10-06 15:11:27 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
1998-10-06 15:11:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The hash caching in our concrete strin classes uses zero to denote
|
1998-10-09 04:24:56 +00:00
|
|
|
* an empty cache value, so we MUST NOT return a hash of zero.
|
1998-10-06 15:11:27 +00:00
|
|
|
*/
|
|
|
|
if (ret == 0)
|
|
|
|
ret = 0xffffffff;
|
1997-09-01 21:59:51 +00:00
|
|
|
return ret;
|
1998-01-08 15:25:59 +00:00
|
|
|
}
|
|
|
|
else
|
1998-10-06 15:11:27 +00:00
|
|
|
return 0xfffffffe; /* Hash for an empty string. */
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
1995-04-03 01:35:42 +00:00
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
// Getting a Shared Prefix
|
|
|
|
|
|
|
|
- (NSString*) commonPrefixWithString: (NSString*)aString
|
|
|
|
options: (unsigned int)mask
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
if (mask & NSLiteralSearch)
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1997-05-03 18:05:21 +00:00
|
|
|
int prefix_len = 0;
|
1997-09-01 21:59:51 +00:00
|
|
|
unichar *u,*w;
|
1998-08-03 15:31:33 +00:00
|
|
|
unichar a1[[self length]+1];
|
|
|
|
unichar *s1 = a1;
|
|
|
|
unichar a2[[aString length]+1];
|
|
|
|
unichar *s2 = a2;
|
1997-05-03 18:05:21 +00:00
|
|
|
u=s1;
|
|
|
|
[self getCharacters:s1];
|
1997-09-01 21:59:51 +00:00
|
|
|
s1[[self length]] = (unichar)0;
|
1997-05-03 18:05:21 +00:00
|
|
|
[aString getCharacters:s2];
|
1997-09-01 21:59:51 +00:00
|
|
|
s2[[aString length]] = (unichar)0;
|
|
|
|
u=s1;
|
|
|
|
w=s2;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (mask & NSCaseInsensitiveSearch)
|
1997-05-03 18:05:21 +00:00
|
|
|
while (*s1 && *s2
|
1997-09-01 21:59:51 +00:00
|
|
|
&& (uni_tolower(*s1) == uni_tolower(*s2)))
|
1997-05-03 18:05:21 +00:00
|
|
|
{
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
prefix_len++;
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
else
|
|
|
|
while (*s1 && *s2
|
|
|
|
&& (*s1 == *s2))
|
|
|
|
{
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
prefix_len++;
|
|
|
|
}
|
|
|
|
return [NSString stringWithCharacters: u length: prefix_len];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
id mySeq, strSeq;
|
|
|
|
NSRange myRange, strRange;
|
|
|
|
unsigned int myLength = [self length];
|
|
|
|
unsigned int strLength = [aString length];
|
|
|
|
unsigned int myIndex = 0;
|
|
|
|
unsigned int strIndex = 0;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (!myLength)
|
1997-09-01 21:59:51 +00:00
|
|
|
return self;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (!strLength)
|
1997-09-01 21:59:51 +00:00
|
|
|
return aString;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (mask & NSCaseInsensitiveSearch)
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
while ((myIndex < myLength) && (strIndex < strLength))
|
|
|
|
if (uni_tolower([self characterAtIndex: myIndex]) ==
|
1997-09-01 21:59:51 +00:00
|
|
|
uni_tolower([aString characterAtIndex: strIndex]))
|
|
|
|
{
|
|
|
|
myIndex++;
|
|
|
|
strIndex++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex];
|
|
|
|
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strIndex];
|
1999-02-04 13:49:27 +00:00
|
|
|
if ((myRange.length < 2) || (strRange.length < 2))
|
1997-09-01 21:59:51 +00:00
|
|
|
return [self substringFromRange: NSMakeRange(0, myIndex)];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mySeq = [NSGSequence sequenceWithString: self range: myRange];
|
|
|
|
strSeq = [NSGSequence sequenceWithString: aString range: strRange];
|
1999-02-04 13:49:27 +00:00
|
|
|
if ([[mySeq lowercase] isEqual: [strSeq lowercase]])
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
|
|
|
myIndex += myRange.length;
|
|
|
|
strIndex += strRange.length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return [self substringFromRange: NSMakeRange(0, myIndex)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [self substringFromRange: NSMakeRange(0, myIndex)];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
while ((myIndex < myLength) && (strIndex < strLength))
|
|
|
|
if ([self characterAtIndex: myIndex] ==
|
1997-09-01 21:59:51 +00:00
|
|
|
[aString characterAtIndex: strIndex])
|
|
|
|
{
|
|
|
|
myIndex++;
|
|
|
|
strIndex++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myIndex];
|
|
|
|
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strIndex];
|
1999-02-04 13:49:27 +00:00
|
|
|
if ((myRange.length < 2) || (strRange.length < 2))
|
1997-09-01 21:59:51 +00:00
|
|
|
return [self substringFromRange: NSMakeRange(0, myIndex)];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mySeq = [NSGSequence sequenceWithString: self range: myRange];
|
|
|
|
strSeq = [NSGSequence sequenceWithString: aString range: strRange];
|
1999-02-04 13:49:27 +00:00
|
|
|
if ([mySeq isEqual: strSeq])
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
|
|
|
myIndex += myRange.length;
|
|
|
|
strIndex += strRange.length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return [self substringFromRange: NSMakeRange(0, myIndex)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [self substringFromRange: NSMakeRange(0, myIndex)];
|
|
|
|
}
|
|
|
|
}
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1998-01-08 15:25:59 +00:00
|
|
|
- (NSRange)lineRangeForRange:(NSRange)aRange
|
|
|
|
{
|
|
|
|
unsigned int startIndex;
|
|
|
|
unsigned int lineEndIndex;
|
|
|
|
|
|
|
|
[self getLineStart: &startIndex
|
|
|
|
end: &lineEndIndex
|
|
|
|
contentsEnd: NULL
|
|
|
|
forRange:aRange];
|
|
|
|
return NSMakeRange(startIndex, lineEndIndex - startIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)getLineStart:(unsigned int *)startIndex
|
|
|
|
end:(unsigned int *)lineEndIndex
|
|
|
|
contentsEnd:(unsigned int *)contentsEndIndex
|
|
|
|
forRange:(NSRange)aRange
|
|
|
|
{
|
|
|
|
unichar thischar;
|
|
|
|
BOOL done;
|
|
|
|
unsigned int start, end, len;
|
|
|
|
|
|
|
|
if (aRange.location > [self length])
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location."];
|
|
|
|
if (aRange.length > ([self length] - aRange.location))
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location+length."];
|
|
|
|
|
|
|
|
len = [self length];
|
|
|
|
start=aRange.location;
|
|
|
|
|
1999-02-04 13:49:27 +00:00
|
|
|
if (startIndex)
|
|
|
|
if (start==0)
|
1998-01-08 15:25:59 +00:00
|
|
|
*startIndex=0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start--;
|
1999-02-04 13:49:27 +00:00
|
|
|
while (start>0)
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
|
|
|
BOOL done = NO;
|
|
|
|
thischar = [self characterAtIndex:start];
|
|
|
|
switch(thischar)
|
|
|
|
{
|
|
|
|
case (unichar)0x000A:
|
|
|
|
case (unichar)0x000D:
|
|
|
|
case (unichar)0x2028:
|
|
|
|
case (unichar)0x2029:
|
|
|
|
done = YES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
start--;
|
|
|
|
break;
|
|
|
|
};
|
1999-02-04 13:49:27 +00:00
|
|
|
if (done)
|
1998-01-08 15:25:59 +00:00
|
|
|
break;
|
|
|
|
};
|
1999-02-04 13:49:27 +00:00
|
|
|
if (start == 0)
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
|
|
|
thischar = [self characterAtIndex:start];
|
|
|
|
switch(thischar)
|
|
|
|
{
|
|
|
|
case (unichar)0x000A:
|
|
|
|
case (unichar)0x000D:
|
|
|
|
case (unichar)0x2028:
|
|
|
|
case (unichar)0x2029:
|
|
|
|
start++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
start++;
|
|
|
|
*startIndex=start;
|
|
|
|
};
|
|
|
|
|
1999-02-04 13:49:27 +00:00
|
|
|
if (lineEndIndex || contentsEndIndex)
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
|
|
|
end=aRange.location+aRange.length;
|
1999-02-04 13:49:27 +00:00
|
|
|
while (end<len)
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
|
|
|
BOOL done = NO;
|
|
|
|
thischar = [self characterAtIndex:end];
|
|
|
|
switch(thischar)
|
|
|
|
{
|
|
|
|
case (unichar)0x000A:
|
|
|
|
case (unichar)0x000D:
|
|
|
|
case (unichar)0x2028:
|
|
|
|
case (unichar)0x2029:
|
|
|
|
done = YES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
end++;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (done)
|
1998-01-08 15:25:59 +00:00
|
|
|
break;
|
|
|
|
};
|
1999-02-04 13:49:27 +00:00
|
|
|
if (end<len)
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
if ([self characterAtIndex:end]==(unichar)0x000D)
|
|
|
|
if ([self characterAtIndex:end+1]==(unichar)0x000A)
|
1998-01-08 15:25:59 +00:00
|
|
|
*lineEndIndex = end+1;
|
|
|
|
else *lineEndIndex = end;
|
|
|
|
else *lineEndIndex = end;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*lineEndIndex = end;
|
|
|
|
};
|
|
|
|
|
1999-02-04 13:49:27 +00:00
|
|
|
if (contentsEndIndex)
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
if (end<len)
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
|
|
|
*contentsEndIndex= end-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
/* xxx OPENSTEP documentation does not say what to do if last
|
|
|
|
line is not terminated. Assume this */
|
|
|
|
*contentsEndIndex= end;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
// Changing Case
|
|
|
|
|
|
|
|
// xxx There is more than this in word capitalization in Unicode,
|
|
|
|
// but this will work in most cases
|
|
|
|
- (NSString*) capitalizedString
|
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
NSZone *z = fastZone(self);
|
1997-05-03 18:05:21 +00:00
|
|
|
unichar *s;
|
|
|
|
int count=0;
|
1998-01-08 15:25:59 +00:00
|
|
|
BOOL found=YES;
|
1997-05-03 18:05:21 +00:00
|
|
|
int len=[self length];
|
1999-02-04 13:49:27 +00:00
|
|
|
|
|
|
|
if (whitespce == nil)
|
|
|
|
setupWhitespce();
|
1998-01-08 15:25:59 +00:00
|
|
|
|
1998-10-15 05:03:16 +00:00
|
|
|
s = NSZoneMalloc(z, sizeof(unichar)*(len+1));
|
1998-01-08 15:25:59 +00:00
|
|
|
[self getCharacters:s];
|
1998-02-03 14:20:00 +00:00
|
|
|
s[len] = (unichar)0;
|
1999-02-04 13:49:27 +00:00
|
|
|
while (count<len)
|
1997-05-03 18:05:21 +00:00
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
if ((*whitespceImp)(whitespce, cMemberSel, s[count]))
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
|
|
|
count++;
|
|
|
|
found=YES;
|
1999-02-04 13:49:27 +00:00
|
|
|
while ((*whitespceImp)(whitespce, cMemberSel, s[count]) && (count < len))
|
1998-01-08 15:25:59 +00:00
|
|
|
count++;
|
|
|
|
};
|
1999-02-04 13:49:27 +00:00
|
|
|
if (found)
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
|
|
|
s[count]=uni_toupper(s[count]);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-02-04 13:49:27 +00:00
|
|
|
while (!(*whitespceImp)(whitespce, cMemberSel, s[count]) && (count < len))
|
1998-01-08 15:25:59 +00:00
|
|
|
{
|
|
|
|
s[count]=uni_tolower(s[count]);
|
|
|
|
count++;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
found=NO;
|
|
|
|
};
|
1998-10-15 05:03:16 +00:00
|
|
|
return [[[NSString alloc] initWithCharactersNoCopy:s length:len fromZone:z] autorelease];
|
1997-05-03 18:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) lowercaseString
|
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
NSZone *z = fastZone(self);
|
1997-05-03 18:05:21 +00:00
|
|
|
unichar *s;
|
|
|
|
int count;
|
|
|
|
int len=[self length];
|
1998-10-15 05:03:16 +00:00
|
|
|
s = NSZoneMalloc(z, sizeof(unichar)*(len+1));
|
1997-05-03 18:05:21 +00:00
|
|
|
for(count=0;count<len;count++)
|
|
|
|
s[count]=uni_tolower([self characterAtIndex:count]);
|
1998-02-03 14:20:00 +00:00
|
|
|
return [[[[self class] alloc] initWithCharactersNoCopy: s
|
|
|
|
length: len
|
1998-10-15 05:03:16 +00:00
|
|
|
fromZone: z] autorelease];
|
1997-05-03 18:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) uppercaseString;
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
NSZone *z = fastZone(self);
|
1997-05-03 18:05:21 +00:00
|
|
|
unichar *s;
|
|
|
|
int count;
|
|
|
|
int len=[self length];
|
1998-10-15 05:03:16 +00:00
|
|
|
s = NSZoneMalloc(z, sizeof(unichar)*(len+1));
|
1997-05-03 18:05:21 +00:00
|
|
|
for(count=0;count<len;count++)
|
|
|
|
s[count]=uni_toupper([self characterAtIndex:count]);
|
1998-02-03 14:20:00 +00:00
|
|
|
return [[[[self class] alloc] initWithCharactersNoCopy: s
|
|
|
|
length: len
|
1998-10-15 05:03:16 +00:00
|
|
|
fromZone: z] autorelease];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Storing the String
|
|
|
|
|
|
|
|
- (NSString*) description
|
|
|
|
{
|
1997-03-03 20:07:35 +00:00
|
|
|
return self;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Getting C Strings
|
|
|
|
|
|
|
|
- (const char*) cString
|
|
|
|
{
|
1995-10-26 01:29:04 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-03 01:35:42 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) cStringLength
|
|
|
|
{
|
1995-10-26 01:29:04 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-03 01:35:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getCString: (char*)buffer
|
|
|
|
{
|
|
|
|
[self getCString:buffer maxLength:NSMaximumStringLength
|
|
|
|
range:((NSRange){0, [self length]})
|
|
|
|
remainingRange:NULL];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getCString: (char*)buffer
|
|
|
|
maxLength: (unsigned int)maxLength
|
|
|
|
{
|
|
|
|
[self getCString:buffer maxLength:maxLength
|
|
|
|
range:((NSRange){0, [self length]})
|
|
|
|
remainingRange:NULL];
|
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
// xxx FIXME adjust range for composite sequence
|
1995-04-03 01:35:42 +00:00
|
|
|
- (void) getCString: (char*)buffer
|
|
|
|
maxLength: (unsigned int)maxLength
|
|
|
|
range: (NSRange)aRange
|
|
|
|
remainingRange: (NSRange*)leftoverRange
|
|
|
|
{
|
1997-05-03 18:05:21 +00:00
|
|
|
int len, count;
|
1995-04-03 01:35:42 +00:00
|
|
|
|
1998-11-19 20:42:06 +00:00
|
|
|
len = [self cStringLength];
|
|
|
|
if (aRange.location > len)
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location."];
|
|
|
|
if (aRange.length > (len - aRange.location))
|
|
|
|
[NSException raise: NSRangeException format:@"Invalid location+length."];
|
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
if (maxLength < aRange.length)
|
|
|
|
{
|
|
|
|
len = maxLength;
|
|
|
|
if (leftoverRange)
|
|
|
|
{
|
|
|
|
leftoverRange->location = 0;
|
|
|
|
leftoverRange->length = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = aRange.length;
|
|
|
|
if (leftoverRange)
|
|
|
|
{
|
|
|
|
leftoverRange->location = aRange.location + maxLength;
|
|
|
|
leftoverRange->length = aRange.length - maxLength;
|
|
|
|
}
|
|
|
|
}
|
1997-05-03 18:05:21 +00:00
|
|
|
count=0;
|
1999-02-04 13:49:27 +00:00
|
|
|
while (count<len)
|
1997-05-03 18:05:21 +00:00
|
|
|
{
|
|
|
|
buffer[count]=unitochar([self characterAtIndex: aRange.location + count]);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
buffer[len] = '\0';
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Getting Numeric Values
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
// xxx Sould we use NSScanner here ?
|
|
|
|
|
1998-10-21 11:56:58 +00:00
|
|
|
- (BOOL) boolValue
|
|
|
|
{
|
|
|
|
if ([self caseInsensitiveCompare: @"YES"] == NSOrderedSame)
|
|
|
|
return YES;
|
|
|
|
return [self intValue] != 0 ? YES : NO;
|
|
|
|
}
|
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
- (double) doubleValue
|
|
|
|
{
|
1998-09-30 07:42:38 +00:00
|
|
|
return atof([self cString]);
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float) floatValue
|
|
|
|
{
|
1998-09-30 07:42:38 +00:00
|
|
|
return (float) atof([self cString]);
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) intValue
|
|
|
|
{
|
1998-09-30 07:42:38 +00:00
|
|
|
return atoi([self cString]);
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Working With Encodings
|
|
|
|
|
|
|
|
+ (NSStringEncoding) defaultCStringEncoding
|
|
|
|
{
|
1998-01-08 15:25:59 +00:00
|
|
|
return _DefaultStringEncoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSStringEncoding*)availableStringEncodings
|
|
|
|
{
|
|
|
|
return _availableEncodings;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSString*)localizedNameOfStringEncoding:(NSStringEncoding)encoding
|
|
|
|
{
|
|
|
|
id ourbundle;
|
|
|
|
id ourname;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Should be path to localizable.strings file.
|
|
|
|
Until we have it, just make shure that bundle
|
|
|
|
is initialized.
|
|
|
|
*/
|
|
|
|
ourbundle = [NSBundle bundleWithPath:@"/"];
|
|
|
|
|
|
|
|
ourname = GetEncodingName(encoding);
|
|
|
|
return [ourbundle
|
|
|
|
localizedStringForKey:ourname
|
|
|
|
value:ourname
|
|
|
|
table:nil];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) canBeConvertedToEncoding: (NSStringEncoding)encoding
|
|
|
|
{
|
1997-09-01 21:59:51 +00:00
|
|
|
id d = [self dataUsingEncoding: encoding allowLossyConversion: NO];
|
|
|
|
return d ? YES : NO;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSData*) dataUsingEncoding: (NSStringEncoding)encoding
|
|
|
|
{
|
1997-09-01 21:59:51 +00:00
|
|
|
return [self dataUsingEncoding: encoding allowLossyConversion: NO];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
// xxx incomplete
|
1995-04-03 01:35:42 +00:00
|
|
|
- (NSData*) dataUsingEncoding: (NSStringEncoding)encoding
|
1999-02-04 22:06:59 +00:00
|
|
|
allowLossyConversion: (BOOL)flag
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1997-09-01 21:59:51 +00:00
|
|
|
int count=0;
|
|
|
|
int len = [self length];
|
|
|
|
|
1999-02-04 13:49:27 +00:00
|
|
|
if ((encoding==NSASCIIStringEncoding)
|
1999-02-04 22:06:59 +00:00
|
|
|
|| (encoding==NSISOLatin1StringEncoding)
|
|
|
|
|| (encoding==NSNEXTSTEPStringEncoding)
|
|
|
|
|| (encoding==NSNonLossyASCIIStringEncoding)
|
|
|
|
|| (encoding==NSSymbolStringEncoding)
|
|
|
|
|| (encoding==NSCyrillicStringEncoding))
|
|
|
|
{
|
|
|
|
char t;
|
|
|
|
unsigned char *buff;
|
|
|
|
|
|
|
|
buff = (unsigned char*)NSZoneMalloc(NSDefaultMallocZone(), len);
|
|
|
|
if (!flag)
|
|
|
|
{
|
|
|
|
for (count = 0; count < len; count++)
|
|
|
|
{
|
|
|
|
t = encode_unitochar([self characterAtIndex: count], encoding);
|
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
buff[count] = t;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSZoneFree(NSDefaultMallocZone(), buff);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* lossy */
|
|
|
|
{
|
|
|
|
for (count = 0; count < len; count++)
|
|
|
|
{
|
|
|
|
t = encode_unitochar([self characterAtIndex: count], encoding);
|
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
buff[count] = t;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* xxx should handle decomposed characters */
|
|
|
|
/* OpenStep documentation is unclear on what to do
|
|
|
|
* if there is no simple replacement for character
|
|
|
|
*/
|
|
|
|
buff[count] = '*';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-05 15:03:29 +00:00
|
|
|
return [NSData dataWithBytesNoCopy: buff length: count];
|
1999-02-04 22:06:59 +00:00
|
|
|
}
|
|
|
|
else if (encoding == NSUnicodeStringEncoding)
|
|
|
|
{
|
|
|
|
unichar *buff;
|
|
|
|
|
|
|
|
buff = (unichar*)NSZoneMalloc(NSDefaultMallocZone(), 2*len+2);
|
|
|
|
buff[0]=0xFEFF;
|
|
|
|
for (count = 0; count < len; count++)
|
|
|
|
buff[count+1] = [self characterAtIndex: count];
|
|
|
|
return [NSData dataWithBytesNoCopy: buff length: 2*len+2];
|
|
|
|
}
|
|
|
|
else /* UTF8 or EUC */
|
|
|
|
{
|
|
|
|
[self notImplemented:_cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
1998-01-08 15:25:59 +00:00
|
|
|
return nil;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSStringEncoding) fastestEncoding
|
|
|
|
{
|
1997-09-01 21:59:51 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-03 01:35:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSStringEncoding) smallestEncoding
|
|
|
|
{
|
1997-09-01 21:59:51 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-03 01:35:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Manipulating File System Paths
|
|
|
|
|
|
|
|
- (unsigned int) completePathIntoString: (NSString**)outputName
|
1998-11-19 20:42:06 +00:00
|
|
|
caseSensitive: (BOOL)flag
|
|
|
|
matchesIntoArray: (NSArray**)outputArray
|
|
|
|
filterTypes: (NSArray*)filterTypes
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1998-10-15 18:46:27 +00:00
|
|
|
NSString * base_path = [self stringByDeletingLastPathComponent];
|
|
|
|
NSString * last_compo = [self lastPathComponent];
|
|
|
|
NSString * tmp_path;
|
|
|
|
NSDirectoryEnumerator * e;
|
1998-11-19 20:42:06 +00:00
|
|
|
NSMutableArray *op;
|
1998-10-15 18:46:27 +00:00
|
|
|
int match_count = 0;
|
|
|
|
|
1998-11-19 20:42:06 +00:00
|
|
|
if (outputArray != 0)
|
|
|
|
op = (NSMutableArray*)[NSMutableArray array];
|
|
|
|
|
1998-10-15 18:46:27 +00:00
|
|
|
if (outputName != NULL) *outputName = nil;
|
|
|
|
|
|
|
|
if ([base_path length] == 0) base_path = @".";
|
|
|
|
|
|
|
|
e = [[NSFileManager defaultManager] enumeratorAtPath: base_path];
|
|
|
|
while (tmp_path = [e nextObject], tmp_path)
|
|
|
|
{
|
|
|
|
/* Prefix matching */
|
|
|
|
if (YES == flag)
|
|
|
|
{ /* Case sensitive */
|
|
|
|
if (NO == [tmp_path hasPrefix: last_compo])
|
|
|
|
continue ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (NO == [[tmp_path uppercaseString]
|
|
|
|
hasPrefix: [last_compo uppercaseString]])
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extensions filtering */
|
|
|
|
if (filterTypes &&
|
|
|
|
(NO == [filterTypes containsObject: [tmp_path pathExtension]]))
|
|
|
|
continue ;
|
|
|
|
|
|
|
|
/* Found a completion */
|
|
|
|
match_count++;
|
|
|
|
if (outputArray != NULL)
|
1998-11-19 20:42:06 +00:00
|
|
|
[*op addObject: tmp_path];
|
1998-10-15 18:46:27 +00:00
|
|
|
|
|
|
|
if ((outputName != NULL) &&
|
1998-11-19 20:42:06 +00:00
|
|
|
((*outputName == nil) || (([*outputName length] < [tmp_path length]))))
|
1998-10-15 18:46:27 +00:00
|
|
|
*outputName = tmp_path;
|
|
|
|
}
|
1998-11-19 20:42:06 +00:00
|
|
|
if (outputArray != NULL)
|
|
|
|
*outputArray = [[op copy] autorelease];
|
1998-10-15 18:46:27 +00:00
|
|
|
return match_count;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1997-11-03 01:40:03 +00:00
|
|
|
/* Return a string for passing to OS calls to handle file system objects. */
|
|
|
|
- (const char*)fileSystemRepresentation
|
|
|
|
{
|
|
|
|
return [self cString];
|
|
|
|
}
|
|
|
|
|
1997-12-08 20:04:16 +00:00
|
|
|
- (BOOL)getFileSystemRepresentation: (char*)buffer maxLength: (unsigned int)size
|
1997-11-03 01:40:03 +00:00
|
|
|
{
|
1998-09-30 07:42:38 +00:00
|
|
|
const char* ptr = [self cString];
|
1997-11-03 01:40:03 +00:00
|
|
|
if (strlen(ptr) > size)
|
|
|
|
return NO;
|
|
|
|
strcpy(buffer, ptr);
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
/* Returns a new string containing the last path component of the receiver. The
|
|
|
|
path component is any substring after the last '/' character. If the last
|
|
|
|
character is a '/', then the substring before the last '/', but after the
|
|
|
|
second-to-last '/' is returned. Returns the receiver if there are no '/'
|
|
|
|
characters. Returns the null string if the receiver only contains a '/'
|
|
|
|
character. */
|
1995-04-03 01:35:42 +00:00
|
|
|
- (NSString*) lastPathComponent
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange range;
|
|
|
|
NSString *substring = nil;
|
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
range = [self rangeOfCharacterFromSet: pathSeps() options: NSBackwardsSearch];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
if (range.length == 0)
|
1997-09-13 17:52:31 +00:00
|
|
|
substring = [[self copy] autorelease];
|
1999-01-20 13:28:28 +00:00
|
|
|
else if (range.location == ([self length] - 1))
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
{
|
|
|
|
if (range.location == 0)
|
1997-09-13 17:52:31 +00:00
|
|
|
substring = [[NSString new] autorelease];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
else
|
1997-09-13 17:52:31 +00:00
|
|
|
substring = [[self substringToIndex:range.location]
|
|
|
|
lastPathComponent];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
}
|
|
|
|
else
|
1999-01-20 13:28:28 +00:00
|
|
|
substring = [self substringFromIndex:range.location + 1];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
|
|
|
|
return substring;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
1997-09-13 17:52:31 +00:00
|
|
|
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
/* Returns a new string containing the path extension of the receiver. The
|
|
|
|
path extension is a suffix on the last path component which starts with
|
|
|
|
a '.' (for example .tiff is the pathExtension for /foo/bar.tiff). Returns
|
|
|
|
a null string if no such extension exists. */
|
1995-04-03 01:35:42 +00:00
|
|
|
- (NSString*) pathExtension
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange range;
|
|
|
|
NSString *substring = nil;
|
|
|
|
|
|
|
|
range = [self rangeOfString:@"." options:NSBackwardsSearch];
|
1999-01-20 18:26:46 +00:00
|
|
|
if (range.length == 0)
|
1997-09-13 17:52:31 +00:00
|
|
|
substring = nil;
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
else
|
1999-01-20 18:26:46 +00:00
|
|
|
{
|
|
|
|
NSRange range2 = [self rangeOfCharacterFromSet: pathSeps()
|
|
|
|
options: NSBackwardsSearch];
|
|
|
|
if (range2.length > 0 && range.location < range2.location)
|
|
|
|
substring = nil;
|
|
|
|
else
|
|
|
|
substring = [self substringFromIndex:range.location + 1];
|
|
|
|
}
|
1997-09-13 17:52:31 +00:00
|
|
|
|
|
|
|
if (!substring)
|
|
|
|
substring = [[NSString new] autorelease];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
return substring;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
/* Returns a new string with the path component given in aString
|
1997-09-18 14:56:47 +00:00
|
|
|
appended to the receiver. Raises an exception if aString starts with
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
a '/'. Checks the receiver to see if the last letter is a '/', if it
|
|
|
|
is not, a '/' is appended before appending aString */
|
1995-04-03 01:35:42 +00:00
|
|
|
- (NSString*) stringByAppendingPathComponent: (NSString*)aString
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange range;
|
|
|
|
NSString *newstring;
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
if ([aString length] == 0)
|
|
|
|
return [[self copy] autorelease];
|
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
range = [aString rangeOfCharacterFromSet: pathSeps()];
|
1997-09-18 14:56:47 +00:00
|
|
|
if (range.length != 0 && range.location == 0)
|
1997-09-01 21:59:51 +00:00
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"attempt to append illegal path component"];
|
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
range = [self rangeOfCharacterFromSet: pathSeps() options: NSBackwardsSearch];
|
1997-09-01 21:59:51 +00:00
|
|
|
if ((range.length == 0 || range.location != [self length] - 1) && [self length] > 0)
|
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
newstring = [self stringByAppendingString: pathSepString];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
else
|
|
|
|
newstring = self;
|
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
return [newstring stringByAppendingString: aString];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
/* Returns a new string with the path extension given in aString
|
1997-09-18 14:56:47 +00:00
|
|
|
appended to the receiver. Raises an exception if aString starts with
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
a '.'. Checks the receiver to see if the last letter is a '.', if it
|
|
|
|
is not, a '.' is appended before appending aString */
|
1995-04-03 01:35:42 +00:00
|
|
|
- (NSString*) stringByAppendingPathExtension: (NSString*)aString
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange range;
|
|
|
|
NSString *newstring;
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
if ([aString length] == 0)
|
|
|
|
return [[self copy] autorelease];
|
|
|
|
|
|
|
|
range = [aString rangeOfString:@"."];
|
1997-09-18 14:56:47 +00:00
|
|
|
if (range.length != 0 && range.location == 0)
|
1997-09-01 21:59:51 +00:00
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"attempt to append illegal path extension"];
|
|
|
|
|
1997-05-03 17:24:31 +00:00
|
|
|
range = [self rangeOfString:@"." options:NSBackwardsSearch];
|
1997-09-01 21:59:51 +00:00
|
|
|
if (range.length == 0 || range.location != [self length] - 1)
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
newstring = [self stringByAppendingString:@"."];
|
|
|
|
else
|
|
|
|
newstring = self;
|
|
|
|
|
|
|
|
return [newstring stringByAppendingString:aString];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
/* Returns a new string with the last path component removed from the
|
|
|
|
receiver. See lastPathComponent for a definition of a path component */
|
1995-04-03 01:35:42 +00:00
|
|
|
- (NSString*) stringByDeletingLastPathComponent
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange range;
|
|
|
|
NSString *substring;
|
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
range = [self rangeOfString: [self lastPathComponent]
|
|
|
|
options: NSBackwardsSearch];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
if (range.length == 0)
|
|
|
|
substring = [[self copy] autorelease];
|
|
|
|
else if (range.location == 0)
|
|
|
|
substring = [[NSString new] autorelease];
|
|
|
|
else if (range.location > 1)
|
1999-01-20 13:28:28 +00:00
|
|
|
substring = [self substringToIndex:range.location-1];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
else
|
1999-01-20 13:28:28 +00:00
|
|
|
substring = pathSepString;
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
return substring;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
/* Returns a new string with the path extension removed from the receiver.
|
|
|
|
See pathExtension for a definition of the path extension */
|
1995-04-03 01:35:42 +00:00
|
|
|
- (NSString*) stringByDeletingPathExtension
|
|
|
|
{
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
NSRange range;
|
|
|
|
NSString *substring;
|
|
|
|
|
|
|
|
range = [self rangeOfString:[self pathExtension] options:NSBackwardsSearch];
|
|
|
|
if (range.length != 0)
|
1999-01-20 13:28:28 +00:00
|
|
|
substring = [self substringToIndex:range.location-1];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
else
|
1999-01-20 13:28:28 +00:00
|
|
|
substring = [[self copy] autorelease];
|
(componentsSeparatedByString:, substringFromRange:,
rangeOfCharacterFromSet:, rangeOfCharacterFromSet:options:,
rangeOfCharacterFromSet:options:range:, rangeOfString:,
rangeOfString:options:, caseInsensitiveCompare:, hasPrefix:,
hasSuffix:, lastPathComponent, pathExtension,
stringByAppendingPathComponent:, stringByAppendingPathExtension:,
stringByDeletingLastPathComponent, stringByDeletingPathExtension):
Implemented methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@505 72102866-910b-0410-8b05-ffd578937521
1995-08-02 15:10:41 +00:00
|
|
|
return substring;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) stringByExpandingTildeInPath
|
|
|
|
{
|
1997-09-01 21:59:51 +00:00
|
|
|
unichar *s;
|
1996-11-24 21:04:24 +00:00
|
|
|
NSString *homedir;
|
|
|
|
NSRange first_slash_range;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
1998-02-03 14:20:00 +00:00
|
|
|
if ([self length] == 0)
|
|
|
|
return [[self copy] autorelease];
|
|
|
|
if ([self characterAtIndex: 0] != 0x007E)
|
1997-09-01 21:59:51 +00:00
|
|
|
return [[self copy] autorelease];
|
1996-11-24 21:04:24 +00:00
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
first_slash_range = [self rangeOfString: pathSepString];
|
1996-11-24 21:04:24 +00:00
|
|
|
|
|
|
|
if (first_slash_range.location != 1)
|
|
|
|
{
|
|
|
|
/* It is of the form `~username/blah/...' */
|
|
|
|
int uname_len;
|
|
|
|
NSString *uname;
|
|
|
|
|
|
|
|
if (first_slash_range.length != 0)
|
|
|
|
uname_len = first_slash_range.length - 1;
|
|
|
|
else
|
|
|
|
/* It is actually of the form `~username' */
|
|
|
|
uname_len = [self length] - 1;
|
|
|
|
uname = [self substringFromRange: ((NSRange){1, uname_len})];
|
|
|
|
homedir = NSHomeDirectoryForUser (uname);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It is of the form `~/blah/...' */
|
|
|
|
homedir = NSHomeDirectory ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%@%@",
|
|
|
|
homedir,
|
|
|
|
[self substringFromIndex: first_slash_range.location]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) stringByAbbreviatingWithTildeInPath
|
|
|
|
{
|
|
|
|
NSString *homedir = NSHomeDirectory ();
|
|
|
|
|
|
|
|
if (![self hasPrefix: homedir])
|
1997-09-01 21:59:51 +00:00
|
|
|
return [[self copy] autorelease];
|
1996-11-24 21:04:24 +00:00
|
|
|
|
1999-01-20 13:28:28 +00:00
|
|
|
return [NSString stringWithFormat: @"~%c%@", (char)pathSepChar,
|
1996-11-24 21:04:24 +00:00
|
|
|
[self substringFromIndex: [homedir length] + 1]];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) stringByResolvingSymlinksInPath
|
|
|
|
{
|
1998-10-15 13:46:35 +00:00
|
|
|
#if defined(__WIN32__) || defined(_WIN32)
|
1995-04-03 01:35:42 +00:00
|
|
|
return self;
|
1998-10-15 13:46:35 +00:00
|
|
|
#else
|
|
|
|
NSString *first_half = self, * second_half = @"";
|
|
|
|
|
|
|
|
const char * tmp_cpath;
|
|
|
|
const int MAX_PATH_LEN = 1024;
|
|
|
|
char tmp_buf[MAX_PATH_LEN];
|
|
|
|
|
|
|
|
int syscall_result;
|
|
|
|
struct stat tmp_stat;
|
|
|
|
|
1999-02-04 13:49:27 +00:00
|
|
|
while (1)
|
1998-10-15 13:46:35 +00:00
|
|
|
{
|
|
|
|
tmp_cpath = [first_half cString];
|
|
|
|
|
|
|
|
syscall_result = lstat(tmp_cpath, &tmp_stat);
|
|
|
|
if (0 != syscall_result) return self ;
|
|
|
|
|
|
|
|
if ((tmp_stat.st_mode & S_IFLNK) &&
|
|
|
|
((syscall_result = readlink(tmp_cpath, tmp_buf, MAX_PATH_LEN)) != -1))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* first half is a path to a symbolic link.
|
|
|
|
*/
|
|
|
|
tmp_buf[syscall_result] = '\0'; // Make a C string
|
|
|
|
second_half = [[NSString stringWithCString: tmp_buf]
|
|
|
|
stringByAppendingPathComponent: second_half];
|
|
|
|
first_half = [first_half stringByDeletingLastPathComponent];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* second_half is an absolute path
|
|
|
|
*/
|
|
|
|
if ([second_half hasPrefix: @"/"])
|
|
|
|
return [second_half stringByResolvingSymlinksInPath];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* first half is NOT a path to a symbolic link
|
|
|
|
*/
|
|
|
|
second_half = [[first_half lastPathComponent]
|
|
|
|
stringByAppendingPathComponent: second_half];
|
|
|
|
first_half = [first_half stringByDeletingLastPathComponent];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* BREAK CONDITION */
|
|
|
|
if ([first_half length] == 0) break;
|
1999-01-20 13:28:28 +00:00
|
|
|
else if ([first_half length] == 1
|
|
|
|
&& [pathSeps() characterIsMember: [first_half characterAtIndex: 0]])
|
1998-10-15 13:46:35 +00:00
|
|
|
{
|
1999-01-20 13:28:28 +00:00
|
|
|
second_half = [pathSepString stringByAppendingPathComponent: second_half];
|
1998-10-15 13:46:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return second_half;
|
|
|
|
#endif /* (__WIN32__) || (_WIN32) */
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) stringByStandardizingPath
|
|
|
|
{
|
1996-11-24 21:04:24 +00:00
|
|
|
NSMutableString *s;
|
|
|
|
NSRange r;
|
|
|
|
|
|
|
|
/* Expand `~' in the path */
|
|
|
|
s = [[self stringByExpandingTildeInPath] mutableCopy];
|
|
|
|
|
|
|
|
/* Remove `/private' */
|
|
|
|
if ([s hasPrefix: @"/private"])
|
|
|
|
[s deleteCharactersInRange: ((NSRange){0,7})];
|
|
|
|
|
|
|
|
/* Condense `//' */
|
1999-01-20 13:28:28 +00:00
|
|
|
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
|
|
|
|
&& r.location + r.length < [s length]
|
|
|
|
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 1]])
|
1996-11-24 21:04:24 +00:00
|
|
|
[s deleteCharactersInRange: r];
|
|
|
|
|
|
|
|
/* Condense `/./' */
|
1999-01-20 13:28:28 +00:00
|
|
|
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
|
|
|
|
&& r.location + r.length < [s length] + 1
|
|
|
|
&& [s characterAtIndex: r.location + 1] == (unichar)'.'
|
|
|
|
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 2]])
|
1996-11-24 21:04:24 +00:00
|
|
|
{
|
1999-01-20 13:28:28 +00:00
|
|
|
r.length++;
|
1996-11-24 21:04:24 +00:00
|
|
|
[s deleteCharactersInRange: r];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Condense `/../' */
|
1999-01-20 13:28:28 +00:00
|
|
|
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
|
|
|
|
&& r.location + r.length < [s length] + 2
|
|
|
|
&& [s characterAtIndex: r.location + 1] == (unichar)'.'
|
|
|
|
&& [s characterAtIndex: r.location + 2] == (unichar)'.'
|
|
|
|
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 3]])
|
1996-11-24 21:04:24 +00:00
|
|
|
{
|
1999-01-20 13:28:28 +00:00
|
|
|
if (r.location > 0)
|
|
|
|
{
|
|
|
|
NSRange r2 = {0, r.location};
|
|
|
|
r = [s rangeOfCharacterFromSet: pathSeps()
|
|
|
|
options: NSBackwardsSearch
|
|
|
|
range: r2];
|
|
|
|
if (r.length == 0)
|
|
|
|
r = r2;
|
|
|
|
r.length += 4; /* Add the `/../' */
|
|
|
|
}
|
1996-11-24 21:04:24 +00:00
|
|
|
[s deleteCharactersInRange: r];
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
// private methods for Unicode level 3 implementation
|
1997-05-03 18:05:21 +00:00
|
|
|
- (int) _baseLength
|
|
|
|
{
|
|
|
|
int count=0;
|
|
|
|
int blen=0;
|
1999-02-04 13:49:27 +00:00
|
|
|
while (count < [self length])
|
|
|
|
if (!uni_isnonsp([self characterAtIndex: count++]))
|
1997-05-03 18:05:21 +00:00
|
|
|
blen++;
|
|
|
|
return blen;
|
|
|
|
}
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
- (NSString*) _normalizedString
|
|
|
|
{
|
|
|
|
#define MAXDEC 18
|
|
|
|
|
1998-10-15 05:03:16 +00:00
|
|
|
NSZone *z = fastZone(self);
|
1997-09-01 21:59:51 +00:00
|
|
|
unichar *u, *upoint;
|
|
|
|
NSRange r;
|
1997-12-08 20:04:16 +00:00
|
|
|
id seq,ret;
|
1997-09-01 21:59:51 +00:00
|
|
|
int len = [self length];
|
|
|
|
int count = 0;
|
1998-10-15 05:03:16 +00:00
|
|
|
|
|
|
|
u = NSZoneMalloc(z, sizeof(unichar)*(len*MAXDEC+1));
|
1997-09-01 21:59:51 +00:00
|
|
|
upoint = u;
|
|
|
|
|
1999-02-04 13:49:27 +00:00
|
|
|
while (count < len)
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
|
|
|
r = [self rangeOfComposedCharacterSequenceAtIndex: count];
|
|
|
|
seq=[NSGSequence sequenceWithString: self range: r];
|
|
|
|
[[seq normalize] getCharacters: upoint];
|
|
|
|
upoint += [seq length];
|
|
|
|
count += r.length;
|
|
|
|
}
|
|
|
|
*upoint = (unichar)0;
|
|
|
|
|
1998-02-03 14:20:00 +00:00
|
|
|
ret = [[[[self class] alloc] initWithCharactersNoCopy: u
|
|
|
|
length: uslen(u)
|
1998-10-15 05:03:16 +00:00
|
|
|
fromZone: z] autorelease];
|
1997-12-08 20:04:16 +00:00
|
|
|
return ret;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
1998-01-21 15:09:22 +00:00
|
|
|
+ (NSString*) pathWithComponents: (NSArray*)components
|
|
|
|
{
|
1998-10-15 13:46:35 +00:00
|
|
|
NSString *s = [components objectAtIndex: 0];
|
1998-01-21 15:09:22 +00:00
|
|
|
int i;
|
|
|
|
|
1998-10-15 13:46:35 +00:00
|
|
|
for (i = 1; i < [components count]; i++) {
|
1998-01-21 15:09:22 +00:00
|
|
|
s = [s stringByAppendingPathComponent: [components objectAtIndex: i]];
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isAbsolutePath
|
|
|
|
{
|
|
|
|
if ([self length] > 0 && [self characterAtIndex: 0] == (unichar)'/') {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*) pathComponents
|
|
|
|
{
|
|
|
|
NSMutableArray *a;
|
|
|
|
NSArray *r;
|
|
|
|
|
|
|
|
a = [[self componentsSeparatedByString: @"/"] mutableCopy];
|
|
|
|
if ([a count] > 0) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* If the path began with a '/' then the first path component must
|
|
|
|
* be a '/' rather than an empty string so that our output could be
|
|
|
|
* fed into [+pathWithComponents:]
|
|
|
|
*/
|
|
|
|
if ([[a objectAtIndex: 0] length] == 0) {
|
|
|
|
[a replaceObjectAtIndex: 0 withObject: @"/"];
|
|
|
|
}
|
|
|
|
/* Any empty path components (except a trailing one) must be removed. */
|
|
|
|
for (i = [a count] - 2; i > 0; i--) {
|
|
|
|
if ([[a objectAtIndex: i] length] == 0) {
|
|
|
|
[a removeObjectAtIndex: i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r = [a copy];
|
|
|
|
[a release];
|
|
|
|
return [r autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*) stringsByAppendingPaths: (NSArray*)paths
|
|
|
|
{
|
|
|
|
NSMutableArray *a;
|
|
|
|
NSArray *r;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
a = [[NSMutableArray alloc] initWithCapacity: [paths count]];
|
|
|
|
for (i = 0; i < [paths count]; i++) {
|
|
|
|
NSString *s = [paths objectAtIndex: i];
|
|
|
|
|
|
|
|
while ([s isAbsolutePath]) {
|
|
|
|
s = [s substringFromIndex: 1];
|
|
|
|
}
|
|
|
|
s = [self stringByAppendingPathComponent: s];
|
|
|
|
[a addObject: s];
|
|
|
|
}
|
|
|
|
r = [a copy];
|
|
|
|
[a release];
|
|
|
|
return [r autorelease];
|
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
+ (NSString*) localizedStringWithFormat: (NSString*) format, ...
|
|
|
|
{
|
|
|
|
[self notImplemented:_cmd];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSComparisonResult) caseInsensitiveCompare: (NSString*)aString
|
|
|
|
{
|
|
|
|
return [self compare:aString options:NSCaseInsensitiveSearch
|
|
|
|
range:((NSRange){0, [self length]})];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) writeToFile: (NSString*)filename
|
|
|
|
atomically: (BOOL)useAuxiliaryFile
|
|
|
|
{
|
1998-01-08 15:25:59 +00:00
|
|
|
id d;
|
1999-02-04 13:49:27 +00:00
|
|
|
if (!(d = [self dataUsingEncoding:[NSString defaultCStringEncoding]]))
|
1998-01-08 15:25:59 +00:00
|
|
|
d = [self dataUsingEncoding: NSUnicodeStringEncoding];
|
|
|
|
return [d writeToFile: filename atomically: useAuxiliaryFile];
|
1997-05-03 18:05:21 +00:00
|
|
|
}
|
|
|
|
|
1998-12-18 17:15:49 +00:00
|
|
|
- (void) descriptionTo: (id<GNUDescriptionDestination>)output
|
1998-01-19 15:20:15 +00:00
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
if ([self length] == 0)
|
|
|
|
{
|
|
|
|
[output appendString: @"\"\""];
|
|
|
|
return;
|
1997-10-31 16:26:44 +00:00
|
|
|
}
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
if (quotables == nil)
|
1999-02-04 13:49:27 +00:00
|
|
|
setupQuotables();
|
1998-01-19 15:20:15 +00:00
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
if ([self rangeOfCharacterFromSet: quotables].length > 0)
|
|
|
|
{
|
|
|
|
const char *cstring = [self cString];
|
|
|
|
const char *from;
|
|
|
|
int len = 0;
|
1998-01-19 15:20:15 +00:00
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
for (from = cstring; *from; from++)
|
|
|
|
{
|
|
|
|
switch (*from)
|
|
|
|
{
|
|
|
|
case '\a':
|
|
|
|
case '\b':
|
|
|
|
case '\t':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
case '\v':
|
|
|
|
case '\f':
|
|
|
|
case '\\':
|
|
|
|
case '\'' :
|
|
|
|
case '"' :
|
|
|
|
len += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (isprint(*from) || *from == ' ')
|
|
|
|
{
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len += 4;
|
|
|
|
}
|
|
|
|
break;
|
1998-01-19 15:20:15 +00:00
|
|
|
}
|
1997-10-31 16:26:44 +00:00
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
char buf[len+3];
|
|
|
|
char *ptr = buf;
|
|
|
|
|
|
|
|
*ptr++ = '"';
|
|
|
|
for (from = cstring; *from; from++)
|
|
|
|
{
|
|
|
|
switch (*from)
|
|
|
|
{
|
|
|
|
case '\a': *ptr++ = '\\'; *ptr++ = 'a'; break;
|
|
|
|
case '\b': *ptr++ = '\\'; *ptr++ = 'b'; break;
|
|
|
|
case '\t': *ptr++ = '\\'; *ptr++ = 't'; break;
|
|
|
|
case '\r': *ptr++ = '\\'; *ptr++ = 'r'; break;
|
|
|
|
case '\n': *ptr++ = '\\'; *ptr++ = 'n'; break;
|
|
|
|
case '\v': *ptr++ = '\\'; *ptr++ = 'v'; break;
|
|
|
|
case '\f': *ptr++ = '\\'; *ptr++ = 'f'; break;
|
|
|
|
case '\\': *ptr++ = '\\'; *ptr++ = '\\'; break;
|
|
|
|
case '\'': *ptr++ = '\\'; *ptr++ = '\''; break;
|
|
|
|
case '"' : *ptr++ = '\\'; *ptr++ = '"'; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (isprint(*from) || *from == ' ')
|
|
|
|
{
|
|
|
|
*ptr++ = *from;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(ptr, "\\%03o", *(unsigned char*)from);
|
|
|
|
ptr = &ptr[4];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*ptr++ = '"';
|
|
|
|
*ptr = '\0';
|
|
|
|
[output appendString: [NSString stringWithCString: buf]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[output appendString: self];
|
1997-10-31 16:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
1997-05-03 18:05:21 +00:00
|
|
|
|
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
/* NSCopying Protocol */
|
|
|
|
|
|
|
|
- copyWithZone: (NSZone*)zone
|
|
|
|
{
|
1998-03-12 14:21:20 +00:00
|
|
|
if ([self isKindOfClass: [NSMutableString class]] ||
|
|
|
|
NSShouldRetainWithZone(self, zone) == NO)
|
|
|
|
return [[[[self class] _concreteClass] allocWithZone:zone]
|
|
|
|
initWithString:self];
|
|
|
|
else
|
|
|
|
return [self retain];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- mutableCopyWithZone: (NSZone*)zone
|
|
|
|
{
|
1995-08-09 16:07:19 +00:00
|
|
|
return [[[[self class] _mutableConcreteClass] allocWithZone:zone]
|
|
|
|
initWithString:self];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1995-04-09 01:53:53 +00:00
|
|
|
/* NSCoding Protocol */
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: anEncoder
|
|
|
|
{
|
1998-10-09 04:24:56 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-09 01:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- initWithCoder: aDecoder
|
|
|
|
{
|
1998-10-09 04:24:56 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
return self;
|
1995-04-09 01:53:53 +00:00
|
|
|
}
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
- (Class) classForArchiver
|
|
|
|
{
|
|
|
|
return [self class];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (Class) classForCoder
|
|
|
|
{
|
|
|
|
return [self class];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (Class) classForPortCoder
|
|
|
|
{
|
|
|
|
return [self class];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder
|
|
|
|
{
|
|
|
|
if ([aCoder isByref] == NO)
|
|
|
|
return self;
|
|
|
|
return [super replacementObjectForPortCoder: aCoder];
|
|
|
|
}
|
|
|
|
|
1999-02-04 13:49:27 +00:00
|
|
|
|
|
|
|
#define inrange(ch,min,max) ((ch)>=(min) && (ch)<=(max))
|
|
|
|
#define char2num(ch) \
|
|
|
|
inrange(ch,'0','9') \
|
|
|
|
? ((ch)-0x30) \
|
|
|
|
: (inrange(ch,'a','f') \
|
|
|
|
? ((ch)-0x57) : ((ch)-0x37))
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const unichar *ptr;
|
|
|
|
unsigned end;
|
|
|
|
unsigned pos;
|
|
|
|
unsigned lin;
|
|
|
|
NSString *err;
|
|
|
|
} pldata;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Property list parsing - skip whitespace keeping count of lines and
|
|
|
|
* regarding objective-c style comments as whitespace.
|
|
|
|
* Returns YES if there is any non-whitespace text remaining.
|
|
|
|
*/
|
|
|
|
static BOOL skipSpace(pldata *pld)
|
|
|
|
{
|
|
|
|
unichar c;
|
|
|
|
|
|
|
|
while (pld->pos < pld->end)
|
|
|
|
{
|
|
|
|
c = pld->ptr[pld->pos];
|
|
|
|
|
|
|
|
if ((*whitespceImp)(whitespce, cMemberSel, c) == NO)
|
|
|
|
{
|
|
|
|
if (c == '/' && pld->pos < pld->end - 1)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Check for comments beginning '//' or '/*'
|
|
|
|
*/
|
|
|
|
if (pld->ptr[pld->pos + 1] == '/')
|
|
|
|
{
|
|
|
|
pld->pos += 2;
|
|
|
|
while (pld->pos < pld->end)
|
|
|
|
{
|
|
|
|
c = pld->ptr[pld->pos];
|
|
|
|
if (c == '\n')
|
|
|
|
break;
|
|
|
|
pld->pos++;
|
|
|
|
}
|
|
|
|
if (pld->pos >= pld->end)
|
|
|
|
{
|
|
|
|
pld->err = @"reached end of string in comment";
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pld->ptr[pld->pos + 1] == '*')
|
|
|
|
{
|
|
|
|
pld->pos += 2;
|
|
|
|
while (pld->pos < pld->end)
|
|
|
|
{
|
|
|
|
c = pld->ptr[pld->pos];
|
|
|
|
if (c == '\n')
|
|
|
|
pld->lin++;
|
|
|
|
else if (c == '*' && pld->pos < pld->end - 1
|
|
|
|
&& pld->ptr[pld->pos+1] == '/')
|
|
|
|
{
|
|
|
|
pld->pos++; /* Skip past '*' */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pld->pos++;
|
|
|
|
}
|
|
|
|
if (pld->pos >= pld->end)
|
|
|
|
{
|
|
|
|
pld->err = @"reached end of string in comment";
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
if (c == '\n')
|
|
|
|
pld->lin++;
|
|
|
|
pld->pos++;
|
|
|
|
}
|
|
|
|
pld->err = @"reached end of string";
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline id parseQuotedString(pldata* pld)
|
|
|
|
{
|
|
|
|
unsigned start = ++pld->pos;
|
1999-02-11 11:05:17 +00:00
|
|
|
unsigned escaped = 0;
|
1999-02-04 13:49:27 +00:00
|
|
|
unsigned shrink = 0;
|
1999-02-11 11:05:17 +00:00
|
|
|
BOOL hex = NO;
|
1999-02-04 13:49:27 +00:00
|
|
|
NSString *obj;
|
|
|
|
|
|
|
|
while (pld->pos < pld->end)
|
|
|
|
{
|
|
|
|
unichar c = pld->ptr[pld->pos];
|
|
|
|
|
|
|
|
if (escaped)
|
|
|
|
{
|
1999-02-11 11:05:17 +00:00
|
|
|
if (escaped == 1 && c == '0')
|
|
|
|
{
|
|
|
|
escaped = 2;
|
|
|
|
hex = NO;
|
|
|
|
}
|
|
|
|
else if (escaped > 1)
|
|
|
|
{
|
|
|
|
if (escaped == 2 && c == 'x')
|
|
|
|
{
|
|
|
|
hex = YES;
|
|
|
|
shrink++;
|
|
|
|
escaped++;
|
|
|
|
}
|
|
|
|
else if (hex && (*hexdigitsImp)(hexdigits, cMemberSel, c))
|
|
|
|
{
|
|
|
|
shrink++;
|
|
|
|
escaped++;
|
|
|
|
}
|
|
|
|
else if (c >= '0' && c <= '7')
|
|
|
|
{
|
|
|
|
shrink++;
|
|
|
|
escaped++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
escaped = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
escaped = 0;
|
|
|
|
}
|
1999-02-04 13:49:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (c == '\\')
|
|
|
|
{
|
1999-02-11 11:05:17 +00:00
|
|
|
escaped = 1;
|
1999-02-04 13:49:27 +00:00
|
|
|
shrink++;
|
|
|
|
}
|
|
|
|
else if (c == '"')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pld->pos++;
|
|
|
|
}
|
|
|
|
if (pld->pos >= pld->end)
|
|
|
|
{
|
|
|
|
pld->err = @"reached end of string while parsing quoted string";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
if (pld->pos - start - shrink == 0)
|
|
|
|
{
|
|
|
|
obj = @"";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unichar chars[pld->pos - start - shrink];
|
|
|
|
unsigned j;
|
|
|
|
unsigned k;
|
|
|
|
|
1999-02-11 11:05:17 +00:00
|
|
|
escaped = 0;
|
|
|
|
hex = NO;
|
1999-02-04 13:49:27 +00:00
|
|
|
for (j = start, k = 0; j < pld->pos; j++)
|
|
|
|
{
|
1999-02-11 11:05:17 +00:00
|
|
|
unichar c = pld->ptr[j];
|
|
|
|
|
1999-02-04 13:49:27 +00:00
|
|
|
if (escaped)
|
|
|
|
{
|
1999-02-11 11:05:17 +00:00
|
|
|
if (escaped == 1 && c == '0')
|
1999-02-04 13:49:27 +00:00
|
|
|
{
|
1999-02-11 11:05:17 +00:00
|
|
|
chars[k] = 0;
|
|
|
|
hex = NO;
|
|
|
|
escaped++;
|
|
|
|
}
|
|
|
|
else if (escaped > 1)
|
|
|
|
{
|
|
|
|
if (escaped == 2 && c == 'x')
|
|
|
|
{
|
|
|
|
hex = YES;
|
|
|
|
escaped++;
|
|
|
|
}
|
|
|
|
else if (hex && (*hexdigitsImp)(hexdigits, cMemberSel, c))
|
|
|
|
{
|
|
|
|
chars[k] <<= 4;
|
|
|
|
chars[k] |= char2num(c);
|
|
|
|
escaped++;
|
|
|
|
}
|
|
|
|
else if (c >= '0' && c <= '7')
|
|
|
|
{
|
|
|
|
chars[k] <<= 3;
|
|
|
|
chars[k] |= (c - '0');
|
|
|
|
escaped++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
escaped = 0;
|
|
|
|
chars[++k] = c;
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
escaped = 0;
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'a' : chars[k] = '\a'; break;
|
|
|
|
case 'b' : chars[k] = '\b'; break;
|
|
|
|
case 't' : chars[k] = '\t'; break;
|
|
|
|
case 'r' : chars[k] = '\r'; break;
|
|
|
|
case 'n' : chars[k] = '\n'; break;
|
|
|
|
case 'v' : chars[k] = '\v'; break;
|
|
|
|
case 'f' : chars[k] = '\f'; break;
|
|
|
|
default : chars[k] = c; break;
|
|
|
|
}
|
|
|
|
k++;
|
1999-02-04 13:49:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-02-11 11:05:17 +00:00
|
|
|
chars[k] = c;
|
|
|
|
if (c == '\\')
|
|
|
|
escaped = 1;
|
1999-02-04 13:49:27 +00:00
|
|
|
else
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
obj = [NSString stringWithCharacters: chars
|
|
|
|
length: pld->pos - start - shrink];
|
|
|
|
}
|
|
|
|
pld->pos++;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline id parseUnquotedString(pldata *pld)
|
|
|
|
{
|
|
|
|
unsigned start = pld->pos;
|
|
|
|
|
|
|
|
while (pld->pos < pld->end)
|
|
|
|
{
|
|
|
|
if ((*quotablesImp)(quotables, cMemberSel, pld->ptr[pld->pos]) == YES)
|
|
|
|
break;
|
|
|
|
pld->pos++;
|
|
|
|
}
|
|
|
|
return [NSString stringWithCharacters: &pld->ptr[start]
|
|
|
|
length: pld->pos-start];
|
|
|
|
}
|
|
|
|
|
|
|
|
static id parsePlItem(pldata* pld)
|
|
|
|
{
|
|
|
|
if (skipSpace(pld) == NO)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
switch (pld->ptr[pld->pos])
|
|
|
|
{
|
|
|
|
case '{':
|
|
|
|
{
|
|
|
|
NSMutableDictionary *dict;
|
|
|
|
|
|
|
|
dict = [NSMutableDictionary dictionaryWithCapacity: 0];
|
|
|
|
pld->pos++;
|
|
|
|
while (skipSpace(pld) == YES && pld->ptr[pld->pos] != '}')
|
|
|
|
{
|
|
|
|
id key;
|
|
|
|
id val;
|
|
|
|
|
|
|
|
key = parsePlItem(pld);
|
|
|
|
if (key == nil)
|
|
|
|
return nil;
|
|
|
|
if (skipSpace(pld) == NO)
|
|
|
|
return nil;
|
|
|
|
if (pld->ptr[pld->pos] != '=')
|
|
|
|
{
|
|
|
|
pld->err = @"unexpected character (wanted '=')";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
pld->pos++;
|
|
|
|
val = parsePlItem(pld);
|
|
|
|
if (val == nil)
|
|
|
|
return nil;
|
|
|
|
if (skipSpace(pld) == NO)
|
|
|
|
return nil;
|
|
|
|
if (pld->ptr[pld->pos] == ';')
|
|
|
|
pld->pos++;
|
|
|
|
else if (pld->ptr[pld->pos] != '}')
|
|
|
|
{
|
|
|
|
pld->err = @"unexpected character (wanted ';' or '}')";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
[dict setObject: val forKey: key];
|
|
|
|
}
|
|
|
|
if (pld->pos >= pld->end)
|
|
|
|
{
|
|
|
|
pld->err = @"unexpected end of string when parsing dictionary";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
pld->pos++;
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '(':
|
|
|
|
{
|
|
|
|
NSMutableArray *array;
|
|
|
|
|
|
|
|
array = [NSMutableArray arrayWithCapacity: 0];
|
|
|
|
pld->pos++;
|
|
|
|
while (skipSpace(pld) == YES && pld->ptr[pld->pos] != ')')
|
|
|
|
{
|
|
|
|
id val;
|
|
|
|
|
|
|
|
val = parsePlItem(pld);
|
|
|
|
if (val == nil)
|
|
|
|
return nil;
|
|
|
|
if (skipSpace(pld) == NO)
|
|
|
|
return nil;
|
|
|
|
if (pld->ptr[pld->pos] == ',')
|
|
|
|
pld->pos++;
|
|
|
|
else if (pld->ptr[pld->pos] != ')')
|
|
|
|
{
|
|
|
|
pld->err = @"unexpected character (wanted ',' or ')')";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
[array addObject: val];
|
|
|
|
}
|
|
|
|
if (pld->pos >= pld->end)
|
|
|
|
{
|
|
|
|
pld->err = @"unexpected end of string when parsing array";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
pld->pos++;
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '<':
|
|
|
|
{
|
|
|
|
NSMutableData *data;
|
|
|
|
unsigned max = pld->end - 1;
|
|
|
|
unsigned char buf[BUFSIZ];
|
|
|
|
unsigned len = 0;
|
|
|
|
|
|
|
|
data = [NSMutableData dataWithCapacity: 0];
|
|
|
|
pld->pos++;
|
|
|
|
while (skipSpace(pld) == YES && pld->ptr[pld->pos] != '>')
|
|
|
|
{
|
|
|
|
while (pld->pos < max
|
|
|
|
&& (*hexdigitsImp)(hexdigits, cMemberSel, pld->ptr[pld->pos])
|
|
|
|
&& (*hexdigitsImp)(hexdigits, cMemberSel, pld->ptr[pld->pos+1]))
|
|
|
|
{
|
|
|
|
unsigned char byte;
|
|
|
|
|
|
|
|
byte = (char2num(pld->ptr[pld->pos])) << 4;
|
|
|
|
pld->pos++;
|
|
|
|
byte |= char2num(pld->ptr[pld->pos]);
|
|
|
|
pld->pos++;
|
|
|
|
buf[len++] = byte;
|
|
|
|
if (len > sizeof(buf))
|
|
|
|
{
|
|
|
|
[data appendBytes: buf length: len];
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pld->pos >= pld->end)
|
|
|
|
{
|
|
|
|
pld->err = @"unexpected end of string when parsing data";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
if (pld->ptr[pld->pos] != '>')
|
|
|
|
{
|
|
|
|
pld->err = @"unexpected character in string";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
[data appendBytes: buf length: len];
|
|
|
|
}
|
|
|
|
pld->pos++;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '"':
|
|
|
|
return parseQuotedString(pld);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return parseUnquotedString(pld);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static id parseSfItem(pldata* pld)
|
|
|
|
{
|
|
|
|
NSMutableDictionary *dict;
|
|
|
|
|
|
|
|
dict = [NSMutableDictionary dictionaryWithCapacity: 0];
|
|
|
|
while (skipSpace(pld) == YES)
|
|
|
|
{
|
|
|
|
id key;
|
|
|
|
id val;
|
|
|
|
|
|
|
|
if (pld->ptr[pld->pos] == '"')
|
|
|
|
key = parseQuotedString(pld);
|
|
|
|
else
|
|
|
|
key = parseUnquotedString(pld);
|
|
|
|
if (key == nil)
|
|
|
|
return nil;
|
|
|
|
if (skipSpace(pld) == NO)
|
|
|
|
{
|
|
|
|
pld->err = @"incomplete final entry (no semicolon?)";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
if (pld->ptr[pld->pos] == ';')
|
|
|
|
{
|
|
|
|
pld->pos++;
|
|
|
|
[dict setObject: @"" forKey: key];
|
|
|
|
}
|
|
|
|
else if (pld->ptr[pld->pos] == '=')
|
|
|
|
{
|
|
|
|
pld->pos++;
|
|
|
|
if (skipSpace(pld) == NO)
|
|
|
|
return nil;
|
|
|
|
if (pld->ptr[pld->pos] == '"')
|
|
|
|
val = parseQuotedString(pld);
|
|
|
|
else
|
|
|
|
val = parseUnquotedString(pld);
|
|
|
|
if (val == nil)
|
|
|
|
return nil;
|
|
|
|
if (skipSpace(pld) == NO)
|
|
|
|
{
|
|
|
|
pld->err = @"missing final semicolon";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
[dict setObject: val forKey: key];
|
|
|
|
if (pld->ptr[pld->pos] == ';')
|
|
|
|
pld->pos++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pld->err = @"unexpected character (wanted ';')";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pld->err = @"unexpected character (wanted '=' or ';')";
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) propertyList
|
|
|
|
{
|
|
|
|
unsigned len = [self length];
|
|
|
|
unichar chars[len];
|
|
|
|
id result;
|
|
|
|
pldata data;
|
|
|
|
|
|
|
|
data.ptr = chars;
|
|
|
|
data.pos = 0;
|
|
|
|
data.end = len;
|
|
|
|
data.lin = 1;
|
|
|
|
data.err = nil;
|
|
|
|
|
|
|
|
[self getCharacters: chars];
|
|
|
|
if (hexdigits == nil)
|
|
|
|
setupHexdigits();
|
|
|
|
if (quotables == nil)
|
|
|
|
setupQuotables();
|
|
|
|
if (whitespce == nil)
|
|
|
|
setupWhitespce();
|
|
|
|
|
|
|
|
result = parsePlItem(&data);
|
|
|
|
|
|
|
|
if (result == nil && data.err != nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"%@ at line %u", data.err, data.lin];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary*) propertyListFromStringsFileFormat
|
|
|
|
{
|
|
|
|
unsigned len = [self length];
|
|
|
|
unichar chars[len];
|
|
|
|
id result;
|
|
|
|
pldata data;
|
|
|
|
|
|
|
|
data.ptr = chars;
|
|
|
|
data.pos = 0;
|
|
|
|
data.end = len;
|
|
|
|
data.lin = 1;
|
|
|
|
data.err = nil;
|
|
|
|
|
|
|
|
[self getCharacters: chars];
|
|
|
|
if (hexdigits == nil)
|
|
|
|
setupHexdigits();
|
|
|
|
if (quotables == nil)
|
|
|
|
setupQuotables();
|
|
|
|
if (whitespce == nil)
|
|
|
|
setupWhitespce();
|
|
|
|
|
|
|
|
result = parseSfItem(&data);
|
|
|
|
if (result == nil && data.err != nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"%@ at line %u", data.err, data.lin];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
@end
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
@implementation NSMutableString
|
|
|
|
|
1995-11-19 20:29:39 +00:00
|
|
|
+ allocWithZone: (NSZone*)z
|
|
|
|
{
|
1997-05-03 17:05:57 +00:00
|
|
|
if ([self class] == [NSMutableString class])
|
|
|
|
return NSAllocateObject([self _mutableConcreteClass], 0, z);
|
|
|
|
return [super allocWithZone:z];
|
1995-11-19 20:29:39 +00:00
|
|
|
}
|
|
|
|
|
1995-04-03 01:35:42 +00:00
|
|
|
// Creating Temporary Strings
|
|
|
|
|
|
|
|
+ (NSMutableString*) stringWithCapacity:(unsigned)capacity
|
|
|
|
{
|
1995-11-19 20:29:39 +00:00
|
|
|
return [[[self alloc] initWithCapacity:capacity]
|
1995-04-03 01:35:42 +00:00
|
|
|
autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Inefficient. */
|
|
|
|
+ (NSString*) stringWithCharacters: (const unichar*)characters
|
|
|
|
length: (unsigned)length
|
|
|
|
{
|
|
|
|
id n;
|
1998-02-03 14:20:00 +00:00
|
|
|
n = [[self alloc] initWithCharacters: characters length: length];
|
|
|
|
return [n autorelease];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSString*) stringWithCString: (const char*)byteString
|
|
|
|
{
|
1998-10-06 15:11:27 +00:00
|
|
|
return [[[NSMutableString_c_concrete_class alloc]
|
|
|
|
initWithCString:byteString]
|
|
|
|
autorelease];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
1998-09-30 07:42:38 +00:00
|
|
|
+ (NSString*) stringWithCString: (const char*)byteString
|
|
|
|
length: (unsigned int)length
|
1995-04-03 01:35:42 +00:00
|
|
|
{
|
1998-10-06 15:11:27 +00:00
|
|
|
return [[[NSMutableString_c_concrete_class alloc]
|
|
|
|
initWithCString:byteString length:length]
|
|
|
|
autorelease];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* xxx Change this when we have non-CString classes */
|
|
|
|
+ (NSString*) stringWithFormat: (NSString*)format, ...
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
self = [super stringWithFormat:format arguments:ap];
|
|
|
|
va_end(ap);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
// Initializing Newly Allocated Strings
|
|
|
|
|
|
|
|
- initWithCapacity:(unsigned)capacity
|
|
|
|
{
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
return self;
|
|
|
|
}
|
1995-04-03 01:35:42 +00:00
|
|
|
|
|
|
|
// Modify A String
|
|
|
|
|
|
|
|
- (void) appendString: (NSString*)aString
|
|
|
|
{
|
1998-01-26 14:18:18 +00:00
|
|
|
NSRange aRange;
|
|
|
|
|
|
|
|
aRange.location = [self length];
|
|
|
|
aRange.length = 0;
|
|
|
|
[self replaceCharactersInRange: aRange withString: aString];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Inefficient. */
|
|
|
|
- (void) appendFormat: (NSString*)format, ...
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
id tmp;
|
|
|
|
va_start(ap, format);
|
1997-10-31 16:26:44 +00:00
|
|
|
tmp = [[NSString alloc] initWithFormat:format arguments:ap];
|
1995-04-03 01:35:42 +00:00
|
|
|
va_end(ap);
|
|
|
|
[self appendString:tmp];
|
1997-10-31 16:26:44 +00:00
|
|
|
[tmp release];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) deleteCharactersInRange: (NSRange)range
|
|
|
|
{
|
1997-12-08 20:04:16 +00:00
|
|
|
[self replaceCharactersInRange:range withString:nil];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) insertString: (NSString*)aString atIndex:(unsigned)loc
|
|
|
|
{
|
1997-12-08 20:04:16 +00:00
|
|
|
NSRange range = {loc, 0};
|
|
|
|
[self replaceCharactersInRange:range withString:aString];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) replaceCharactersInRange: (NSRange)range
|
|
|
|
withString: (NSString*)aString
|
|
|
|
{
|
1997-12-08 20:04:16 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setString: (NSString*)aString
|
|
|
|
{
|
1997-12-08 20:04:16 +00:00
|
|
|
NSRange range = {0, [self length]};
|
|
|
|
[self replaceCharactersInRange:range withString:aString];
|
1995-04-03 01:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|