~ubuntu-branches/ubuntu/edgy/gnustep-base/edgy

« back to all changes in this revision

Viewing changes to Source/NSString.m

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2005-09-11 12:16:07 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050911121607-cqyghsqpbjwqva0i
Tags: 1.10.3-2build1
RebuildĀ forĀ dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
28
28
 
29
29
   <title>NSString class reference</title>
30
 
   $Date: 2004/09/27 21:32:45 $ $Revision: 1.328 $
 
30
   $Date: 2005/04/12 18:12:43 $ $Revision: 1.332.2.1 $
31
31
*/
32
32
 
33
33
/* Caveats:
1739
1739
 * be at index 0, 1, and 2).<br />
1740
1740
 * If the supplied index is greater than or equal to the length of the
1741
1741
 * receiver an exception is raised.
1742
 
 */ 
 
1742
 */
1743
1743
- (NSString*) substringFromIndex: (unsigned int)index
1744
1744
{
1745
1745
  return [self substringWithRange: ((NSRange){index, [self length]-index})];
1752
1752
 * the first three characters of the receiver.<br />
1753
1753
 * If the supplied index is greater than the length of the receiver
1754
1754
 * an exception is raised.
1755
 
 */ 
 
1755
 */
1756
1756
- (NSString*) substringToIndex: (unsigned int)index
1757
1757
{
1758
1758
  return [self substringWithRange: ((NSRange){0,index})];;
2411
2411
    {
2412
2412
      BOOL found = NO;
2413
2413
      end = aRange.location;
2414
 
      if(aRange.length)
 
2414
      if (aRange.length)
2415
2415
        {
2416
2416
          end += (aRange.length - 1);
2417
2417
        }
2609
2609
// Getting C Strings
2610
2610
 
2611
2611
/**
 
2612
 * Returns a pointer to a null terminated string of 16-bit unichar
 
2613
 * The memory pointed to is not owned by the caller, so the
 
2614
 * caller must copy its contents to keep it.
 
2615
 */
 
2616
- (const unichar*) unicharString
 
2617
{
 
2618
  NSMutableData *data;
 
2619
  unichar       *uniStr;
 
2620
 
 
2621
  data = [NSMutableData dataWithLength: ([self length] + 1) * sizeof(unichar)];
 
2622
  uniStr = (unichar*)[data mutableBytes];
 
2623
  if (uniStr != 0)
 
2624
    {
 
2625
      [self getCharacters: uniStr];
 
2626
    }
 
2627
  return uniStr;
 
2628
}
 
2629
 
 
2630
/**
2612
2631
 * Returns a pointer to a null terminated string of 8-bit characters in the
2613
2632
 * default encoding.  The memory pointed to is not owned by the caller, so the
2614
2633
 * caller must copy its contents to keep it.  Raises an
3177
3196
  return match_count;
3178
3197
}
3179
3198
 
 
3199
static NSFileManager *fm = nil;
 
3200
 
3180
3201
/**
3181
3202
 * Converts this string, which is assumed to be a path in Unix notation ('/'
3182
3203
 * is file separator, '.' is extension separator) to a C string path expressed
3186
3207
 */
3187
3208
- (const char*) fileSystemRepresentation
3188
3209
{
3189
 
  static NSFileManager *fm = nil;
3190
 
 
3191
3210
  if (fm == nil)
3192
3211
    {
3193
3212
      fm = RETAIN([NSFileManager defaultManager]);
3198
3217
 
3199
3218
/**
3200
3219
 * Converts this string, which is assumed to be a path in Unix notation ('/'
 
3220
 * is file separator, '.' is extension separator) to a string path expressed
 
3221
 * in the convention for the host operating system.
 
3222
 */
 
3223
- (NSString*) localFromOpenStepPath
 
3224
{
 
3225
  if (fm == nil)
 
3226
    {
 
3227
      fm = RETAIN([NSFileManager defaultManager]);
 
3228
    }
 
3229
 
 
3230
  return [fm localFromOpenStepPath: self];
 
3231
}       
 
3232
 
 
3233
/**
 
3234
 * Converts this string, which is assumed to be a path in the convention
 
3235
 * for the host operating system to a string path expressed
 
3236
 * in Unix notation ('/' is file separator, '.' is extension separator).
 
3237
 */
 
3238
- (NSString*) openStepPathFromLocal
 
3239
{
 
3240
  if (fm == nil)
 
3241
    {
 
3242
      fm = RETAIN([NSFileManager defaultManager]);
 
3243
    }
 
3244
 
 
3245
  return [fm openStepPathFromLocal: self];
 
3246
}       
 
3247
 
 
3248
 
 
3249
/**
 
3250
 * Converts this string, which is assumed to be a path in Unix notation ('/'
3201
3251
 * is file separator, '.' is extension separator) to a C string path expressed
3202
3252
 * in the convention for the host operating system.  This string will be
3203
3253
 * stored into buffer if it is shorter than size, otherwise NO is returned.
3212
3262
  return YES;
3213
3263
}
3214
3264
 
 
3265
 
3215
3266
/**
3216
3267
 * Returns a string containing the last path component of the receiver.<br />
3217
3268
 * The path component is the last non-empty substring delimited by the ends
3358
3409
        {
3359
3410
          if (pathSepMember(buf[aLength]) == YES)
3360
3411
            {
 
3412
              buf[aLength] = '/';       // Standardise
3361
3413
              if (pathSepMember(buf[aLength-1]) == YES)
3362
3414
                {
3363
3415
                  unsigned      pos;
3364
3416
 
 
3417
                  buf[aLength-1] = '/'; // Standardise
3365
3418
                  for (pos = aLength+1; pos < length; pos++)
3366
3419
                    {
3367
3420
                      buf[pos-1] = buf[pos];
3684
3737
 */
3685
3738
- (NSString*) stringByReplacingPercentEscapesUsingEncoding: (NSStringEncoding)e
3686
3739
{
3687
 
  NSMutableData *d; 
 
3740
  NSMutableData *d;
3688
3741
  NSString      *s = nil;
3689
3742
 
3690
3743
  d = [[self dataUsingEncoding: NSASCIIStringEncoding] mutableCopy];
4449
4502
{
4450
4503
  if ([aCoder allowsKeyedCoding])
4451
4504
    {
4452
 
      NSString *string = (NSString*)[(NSKeyedUnarchiver*)aCoder 
 
4505
      NSString *string = (NSString*)[(NSKeyedUnarchiver*)aCoder
4453
4506
                             _decodePropertyListForKey: @"NS.string"];
4454
4507
 
4455
4508
      self = [self initWithString: string];
4464
4517
        {
4465
4518
          NSStringEncoding      enc;
4466
4519
          NSZone                *zone;
4467
 
          
 
4520
        
4468
4521
          [aCoder decodeValueOfObjCType: @encode(NSStringEncoding) at: &enc];
4469
4522
#if     GS_WITH_GC
4470
4523
          zone = GSAtomicMallocZone();
4471
4524
#else
4472
4525
          zone = GSObjCZone(self);
4473
4526
#endif
4474
 
          
 
4527
        
4475
4528
          if (enc == NSUnicodeStringEncoding)
4476
4529
            {
4477
4530
              unichar   *chars;
4478
 
              
 
4531
        
4479
4532
              chars = NSZoneMalloc(zone, count*sizeof(unichar));
4480
4533
              [aCoder decodeArrayOfObjCType: @encode(unichar)
4481
4534
                                      count: count
4488
4541
            || enc == _DefaultStringEncoding)
4489
4542
            {
4490
4543
              unsigned char     *chars;
4491
 
              
 
4544
        
4492
4545
              chars = NSZoneMalloc(zone, count+1);
4493
4546
              [aCoder decodeArrayOfObjCType: @encode(unsigned char)
4494
4547
                                      count: count
4513
4566
            {
4514
4567
              unsigned char     *chars;
4515
4568
              NSData    *data;
4516
 
              
 
4569
        
4517
4570
              chars = NSZoneMalloc(zone, count);
4518
4571
              [aCoder decodeArrayOfObjCType: @encode(unsigned char)
4519
4572
                                      count: count
4628
4681
 * followed by a semicolon.  In this case, the value for that key is
4629
4682
 * assumed to be an empty string.
4630
4683
 * </p>
4631
 
 * <example>  
 
4684
 * <example>
4632
4685
 *   // Strings file entries follow -
4633
4686
 *   key1 = " a string value";
4634
4687
 *   key2;      // This key has an empty string as a value.
4635
4688
 *   "Another key" = "a longer string value for th third key";
4636
 
 * </example>  
 
4689
 * </example>
4637
4690
 */
4638
4691
- (NSDictionary*) propertyListFromStringsFileFormat
4639
4692
{