- Issue 63 fix by thinker at thinkertons.com, odd length unicode on pasteboard

- Issue 64 fix by thinker at thinkertons.com -[NSDictionary keysSortedByValueUsingSelector:]  implementation
- Issue 65 fix by thinker at thinkertons.com -[NSString getLineStart🔚contentsEnd:forRange:] fix
- Issue 66 fix by thinker at thinkertons.com, NSStringWithDateFormatLocale() missing %e format
- Issue 67 fix by thinker at thinkertons.com, -[NSDate description] "unimplemented"
- Rolf Jansen's NSStringFormatter partial fix for alternate formats
- glext.h made public
This commit is contained in:
Christopher Lloyd 2008-02-04 06:27:14 +00:00
parent 56d74a9e06
commit 4828f93eba
9 changed files with 133 additions and 43 deletions

View File

@ -206,18 +206,43 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
case TYMED_ENHMF: // hEnhMetaFile
break;
case TYMED_HGLOBAL:{ // hGlobal
void *bytes=GlobalLock(storageMedium.hGlobal);
int size=GlobalSize(storageMedium.hGlobal);
if(formatEtc.cfFormat==CF_UNICODETEXT && size>1)
size-=2; // remove trailing zero
result=[NSData dataWithBytes:bytes length:size];
GlobalUnlock(storageMedium.hGlobal);
}
break;
case TYMED_HGLOBAL:
{ // hGlobal
void *bytes=GlobalLock(storageMedium.hGlobal);
int size=GlobalSize(storageMedium.hGlobal);
if(formatEtc.cfFormat==CF_UNICODETEXT && (size > 0))
{
if(size % 2)
{ // odd data length. WTF?
unsigned char lastbyte = ((unsigned char *)bytes)[size-1];
if(lastbyte != 0)
{ // not a null oddbyte, log it.
NSString * str = [NSString stringWithCharacters: bytes length: (size-1)/2];
if([str length] > 80)
{
str = [str substringFromIndex: [str length] - 80];
}
NSLog(@"%s:%u[%s] -- \n*****CF_UNICODETEXT byte count not even and odd byte (%0X,'%c') not null",__FILE__, __LINE__, __PRETTY_FUNCTION__,(unsigned)lastbyte,
lastbyte);
}
--size; // truncate regardless
}
while(size)
{ // zortch any terminating null unichars
if(((unichar *) bytes)[(size-2)/2] != 0)
{
break;
}
else
{
size -= 2;
}
};
}
result=[NSData dataWithBytes:bytes length:size];
GlobalUnlock(storageMedium.hGlobal);
}
break;
case TYMED_FILE: // lpszFileName
break;

View File

@ -197,8 +197,7 @@ const NSTimeInterval NSTimeIntervalSince1970=978307200.0L;
}
-(NSString *)description {
NSUnimplementedMethod();
return [super description];
return [self descriptionWithLocale:nil];
}
-(NSString *)descriptionWithLocale:(NSDictionary *)locale {

View File

@ -386,7 +386,13 @@ NSString *NSStringWithDateFormatLocale(NSTimeInterval interval,NSString *format,
}
break;
case 'F':{
case 'e':{
id fmt=@"%d";
[result appendFormat:fmt,NSDayOfMonthFromTimeInterval(interval)+1];
}
break;
case 'F':{
id fmt=(suppressZero)?@"%d":((fillChar==' ')?@"%3d":@"%03d");
[result appendFormat:fmt,NSMillisecondsFromTimeInterval(interval)];

View File

@ -27,8 +27,4 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return [self retain];
}
-(NSString *)description {
return [NSString stringWithFormat:@"<%@[0x%lx] time: %f>", [self class], self, (float)_timeIntervalSinceReferenceDate];
}
@end

View File

@ -18,6 +18,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <Foundation/NSCoder.h>
#import <Foundation/NSKeyedUnarchiver.h>
#import <Foundation/NSURL.h>
#import <Foundation/NSAutoreleasePool.h>
@implementation NSDictionary
@ -333,10 +334,22 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return result;
}
-(NSArray *)keysSortedByValueUsingSelector:(SEL)selector {
NSUnimplementedMethod();
return nil;
}
- (NSArray *) keysSortedByValueUsingSelector: (SEL)selector
{ // there is probably a faster implementation, but at least this is easy to understand.
NSMutableArray * result = nil;
NSAutoreleasePool * pool = [NSAutoreleasePool new];
NSArray * values = [[self allValues] sortedArrayUsingSelector: selector];
id value;
NSEnumerator * de = [values objectEnumerator];
result = [NSMutableArray array];
while((value = [de nextObject]))
{
[result addObjectsFromArray: [self allKeysForObject: value]];
}
result = [result copy];
[pool release];
return [result autorelease];
}
-(NSArray *)allValues {
int i,count=[self count];

View File

@ -8,6 +8,23 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <Foundation/NSLocale.h>
#import <Foundation/NSRaise.h>
NSString *NSLocaleCountryCode=@"NSLocaleCountryCode";
NSString *NSLocaleLanguageCode=@"NSLocaleLanguageCode";
NSString *NSLocaleVariantCode=@"NSLocaleVariantCode";
NSString *NSLocaleIdentifier=@"NSLocaleIdentifier";
NSString *NSLocaleGroupingSeparator=@"NSLocaleGroupingSeparator";
NSString *NSLocaleDecimalSeparator=@"NSLocaleDecimalSeparator";
NSString *NSLocaleCalendar=@"NSLocaleCalendar";
NSString *NSLocaleCurrencyCode=@"NSLocaleCurrencyCode";
NSString *NSLocaleCurrencySymbol=@"NSLocaleCurrencySymbol";
NSString *NSLocaleUsesMetricSystem=@"NSLocaleUsesMetricSystem";
NSString *NSLocaleMeasurementSystem=@"NSLocaleMeasurementSystem";
NSString *NSLocaleScriptCode=@"NSLocaleScriptCode";
NSString *NSLocaleExemplarCharacterSet=@"NSLocaleExemplarCharacterSet";
NSString *NSLocaleCollationIdentifier=@"NSLocaleCollationIdentifier";
@implementation NSLocale
+systemLocale {

View File

@ -659,6 +659,11 @@ U+2029 (Unicode paragraph separator), \r\n, in that order (also known as CRLF)
}
}
if((end >= length) && (state!=done))
{
contentsEnd = end;
}
if(startp!=NULL)
*startp=start;
if(endp!=NULL)

View File

@ -7,6 +7,7 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
// Original - Christopher Lloyd <cjwl@objc.net>
#import <Foundation/NSLocale.h>
#import <Foundation/NSStringFormatter.h>
#import <Foundation/NSString_unicodePtr.h>
#import <Foundation/NSString_cString.h> //appendCString
@ -180,7 +181,7 @@ static inline void appendCStringChar(NSStringBuffer *buffer,char c,
static inline void appendFloat(NSStringBuffer *buffer,double value,
unichar fillChar,BOOL leftAdj,BOOL plusSign,BOOL spaceSign,
int fieldWidth,int precision,BOOL gFormat){
int fieldWidth,int precision,BOOL gFormat,BOOL altForm,NSDictionary *locale){
if(1.0/0.0==value)
appendCString(buffer,"1.#INF00",' ',leftAdj,fieldWidth);
else if(log(0)==value)
@ -189,20 +190,31 @@ static inline void appendFloat(NSStringBuffer *buffer,double value,
appendCString(buffer,"NaN",' ',leftAdj,fieldWidth);
else{
double integral,fractional,power;
unsigned i,length=0;
unsigned i,j,length=0;
unichar characters[100];
unichar sign=(value<0)?'-':plusSign?'+':spaceSign?' ':'\0';
power=pow(10.0,precision);
value=round(fabs(value)*power)/power;
if (value != 0.0)
{
value=fabs(value);
if (!gFormat)
power=pow(10.0,precision);
else
power=pow(10.0,precision-1-floor(log10(value)));
value=(1.0 + 1.0e-15)*round(value*power)/power;
}
fractional=modf(value,&integral);
BOOL intZero=integral<1.0;
while(integral>=1.0){
characters[length++]=(unichar)floor(fmod(integral,10.0)+'0');
characters[length++]=(unichar)fmod(integral,10.0)+'0';
integral/=10.0;
}
if(gFormat)
precision -= length;
if(length==0)
characters[length++]='0';
if(sign)
@ -211,18 +223,38 @@ static inline void appendFloat(NSStringBuffer *buffer,double value,
reverseCharacters(characters,length);
if(precision>0){
char decSep;
if (locale)
decSep = [(NSString *)[locale objectForKey:NSLocaleDecimalSeparator] characterAtIndex:0];
else
decSep = [(NSString *)[[NSLocale systemLocale] objectForKey:NSLocaleDecimalSeparator] characterAtIndex:0];
unsigned start=length;
BOOL allZeros=YES;
characters[length++]='.';
for(i=0;i<precision;i++,length++){
BOOL fractZero=YES;
characters[length++]=decSep;
for(i=0,j=0;i<precision;i++,j++,length++){
fractional*=10.0;
if((characters[length]=(unichar)floor(fmod(fractional,10.0)+'0'))!='0')
allZeros=NO;
if((characters[length]=(unichar)fmod(fractional,10.0)+'0')!='0')
fractZero=NO;
else if (gFormat && intZero && fractZero && (j - i) < 5)
i--;
}
if(gFormat && allZeros)
length=start;
if (gFormat)
{
if (intZero && fractZero)
if(altForm)
length=start + precision;
else
length=start;
else if(!altForm)
{
while (characters[length-1] == '0')
length--;
if (characters[length-1] == decSep)
length--;
}
}
}
appendCharacters(buffer,characters,length,fillChar,leftAdj,fieldWidth);
@ -476,8 +508,7 @@ unichar *NSCharactersNewWithFormat(NSString *format,NSDictionary *locale,
else
value=va_arg(arguments,double);
appendFloat(&result,value,fillChar,leftAdj,plusSign,
spaceSign,fieldWidth,precision,NO);
appendFloat(&result,value,fillChar,leftAdj,plusSign,spaceSign,fieldWidth,precision,NO,NO,locale);
}
break;
@ -489,8 +520,7 @@ unichar *NSCharactersNewWithFormat(NSString *format,NSDictionary *locale,
else
value=va_arg(arguments,double);
appendFloat(&result,value,fillChar,leftAdj,plusSign,
spaceSign,fieldWidth,precision,NO);
appendFloat(&result,value,fillChar,leftAdj,plusSign,spaceSign,fieldWidth,precision,NO,NO,locale);
}
break;
@ -502,8 +532,7 @@ unichar *NSCharactersNewWithFormat(NSString *format,NSDictionary *locale,
else
value=va_arg(arguments,double);
appendFloat(&result,value,fillChar,leftAdj,plusSign,
spaceSign,fieldWidth,precision,YES);
appendFloat(&result,value,fillChar,leftAdj,plusSign,spaceSign,fieldWidth,precision,YES,altForm,locale);
}
break;

View File

@ -7,7 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
FE3B34AA0D55939B009E0AA5 /* glext.h in Headers */ = {isa = PBXBuildFile; fileRef = FE3B34A90D55939B009E0AA5 /* glext.h */; };
FE3B34AA0D55939B009E0AA5 /* glext.h in Headers */ = {isa = PBXBuildFile; fileRef = FE3B34A90D55939B009E0AA5 /* glext.h */; settings = {ATTRIBUTES = (Public, ); }; };
FEF2EB230C878C88001FC5A8 /* OpenGL.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF2EB220C878C88001FC5A8 /* OpenGL.h */; settings = {ATTRIBUTES = (Public, ); }; };
FEF2EB5E0C87B894001FC5A8 /* gl.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF2EB5D0C87B894001FC5A8 /* gl.h */; settings = {ATTRIBUTES = (Public, ); }; };
FEF2EB680C87B8BA001FC5A8 /* glu.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF2EB670C87B8BA001FC5A8 /* glu.h */; settings = {ATTRIBUTES = (Public, ); }; };