Frameworks/AIUtilities Framework/Source/AIStringAdditions.m
branchadium-1.5.10.5
changeset 5997 d88e6711d0e0
parent 4897 5ea3bd51010d
equal deleted inserted replaced
5996:1894c44cfd13 5997:d88e6711d0e0
   185 	NSMutableString	*newString = [NSMutableString string];
   185 	NSMutableString	*newString = [NSMutableString string];
   186 	NSUInteger		i, length = [self length];
   186 	NSUInteger		i, length = [self length];
   187 
   187 
   188 	for (i = 0 ; i < length ; i++) {
   188 	for (i = 0 ; i < length ; i++) {
   189 		/* Offset by the desired amount */
   189 		/* Offset by the desired amount */
   190 		[newString appendFormat:@"%C",([self characterAtIndex:i] + offset)];
   190 		[newString appendFormat:@"%C",(unichar)([self characterAtIndex:i] + offset)];
   191 	}
   191 	}
   192 	
   192 	
   193 	return newString;
   193 	return newString;
   194 }
   194 }
   195 
   195 
   754 	//012345678 <-Indices.
   754 	//012345678 <-Indices.
   755 	//42.123400 <-Assuming numDigits = 6.
   755 	//42.123400 <-Assuming numDigits = 6.
   756 	//^-----^   <-Returns this substring. (Trailing zeroes are deleted.)
   756 	//^-----^   <-Returns this substring. (Trailing zeroes are deleted.)
   757 	//42.000000
   757 	//42.000000
   758 	//^^        <-Returns this substring (everything before the decimal point) for a whole number.
   758 	//^^        <-Returns this substring (everything before the decimal point) for a whole number.
   759 	NSString *format = numDigits ? [NSString stringWithFormat:@"%%.%uf", numDigits] : @"%f";
   759 	NSString *format = numDigits ? [NSString stringWithFormat:@"%%.%uf", (unsigned int)numDigits] : @"%f";
   760 	NSString *str = [NSString stringWithFormat:format, (double)f];
   760 	NSString *str = [NSString stringWithFormat:format, (double)f];
   761 	NSUInteger i = [str length];
   761 	NSUInteger i = [str length];
   762 	while (i-- > 0) {
   762 	while (i-- > 0) {
   763 		if ([str characterAtIndex:i] != '0') {
   763 		if ([str characterAtIndex:i] != '0') {
   764 			//If we have run out of zeroes, this is a whole number. Leave off the decimal point.
   764 			//If we have run out of zeroes, this is a whole number. Leave off the decimal point.