RSInline RSTypeRef ___RSProcessInfoCreateUpdate(RSStringRef key) { RSUInteger size = 0; RSCBuffer ckey = nil; RSTypeRef value = nil; if (!key || key == (RSStringRef)RSNil) return nil; if (kSuccess == ____RSProcessInfoUpdate(ckey = RSStringGetCStringPtr(key, RSStringEncodingMacRoman), nil, &size)) { void *buf = RSAllocatorAllocate(RSAllocatorSystemDefault, size); if (kSuccess == ____RSProcessInfoUpdate(ckey, buf, &size)) { if (!RSStringHasSuffix(key, RSSTR("size"))) value = RSStringCreateWithCString(RSAllocatorSystemDefault, buf, RSStringEncodingUTF8); else { if (size == sizeof(unsigned long long)) value = RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("%lld"), *(unsigned long long*)buf); else if (size == sizeof(unsigned long)) value = RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("%ld"), *(unsigned long*)buf); else if (size == sizeof(double)) value = RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("%f"), *(float*)buf); } } RSAllocatorDeallocate(RSAllocatorSystemDefault, buf); } return value; }
static RSTypeRef __RSErrorRSCoreFoundationCallBack(RSErrorRef err, RSStringRef key) { if (!RSEqual(key, RSErrorDescriptionKey) && !RSEqual(key, RSErrorLocalizedFailureReasonKey)) return nil; RSStringRef errStr = nil; struct __RSErrorPrivateFormatTable cFormat = __RSErrorDomainRSCoreFoundationGetCStringWithCode(RSErrorGetCode(err)); if (cFormat.argsCnt) { RSStringRef format = RSStringCreateWithCString(RSAllocatorSystemDefault, cFormat.format, RSStringEncodingUTF8); RSArrayRef objects = RSDictionaryGetValue(__RSErrorGetUserInfo(err), RSErrorTargetKey); RSTypeRef object[3] = {nil}; RSIndex minCnt = 0; if (objects) { minCnt = min(cFormat.argsCnt, RSArrayGetCount(objects)); switch (minCnt) { case 1: object[0] = RSArrayObjectAtIndex(objects, 0); errStr = RSStringCreateWithFormat(RSAllocatorSystemDefault, format, object[0]); break; case 2: object[0] = RSArrayObjectAtIndex(objects, 0); object[1] = RSArrayObjectAtIndex(objects, 1); errStr = RSStringCreateWithFormat(RSAllocatorSystemDefault, format, object[0], object[1]); break; case 3: object[0] = RSArrayObjectAtIndex(objects, 0); object[1] = RSArrayObjectAtIndex(objects, 1); object[2] = RSArrayObjectAtIndex(objects, 2); errStr = RSStringCreateWithFormat(RSAllocatorSystemDefault, format, object[0], object[1], object[2]); break; default: HALTWithError(RSInvalidArgumentException, "the formate is too long to support"); break; } } for (RSIndex idx = 0; idx < minCnt; idx++) { RSRelease(object[idx]); } RSRelease(format); } else { errStr = RSStringCreateWithCString(RSAllocatorSystemDefault, cFormat.format, RSStringEncodingUTF8); } return errStr; }
static void __RSFileManagerContentContextAddContent(__RSFileManagerContentsContext* context, RSStringRef obj) { if (context == nil) return; #if __RSFileManagerContentsContextDoNotUseRSArray if (context->spaths == nil) { if (NO == __RSFileManagerContentContextReAllocate(RSAllocatorSystemDefault, context, 64)) return; } if (context->spaths) { if (context->numberOfContents >= context->capacity) { if (NO == __RSFileManagerContentContextReAllocate(RSAllocatorSystemDefault, context, context->capacity*2)) return; } __RSRuntimeMemoryBarrier(); context->spaths[context->numberOfContents++] = (obj); } #else if (context->contain == nil) context->contain = RSArrayCreateMutable(RSAllocatorSystemDefault, 32); if (context->dirStack == nil) context->dirStack = RSArrayCreateMutable(RSAllocatorSystemDefault, 32); RSStringRef fullObj = nil; if (context->currentPrefix) { fullObj = RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("%R/%R"), context->currentPrefix, obj); RSArrayAddObject(context->contain, fullObj); RSRelease(fullObj); } else { RSArrayAddObject(context->contain, obj); } #endif }
RSExport RSStringRef RSErrorCopyDescription(RSErrorRef err) { __RSAssertIsError(err); RSStringRef result = __RSErrorCopyUserInfoKey(err, RSErrorLocalizedDescriptionKey), reason = nil; if (result == nil) { reason = __RSErrorCopyUserInfoKey(err, RSErrorLocalizedFailureReasonKey); if (reason) result = RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("The operation couldn't be completed. %R"), reason); else if ((reason = __RSErrorCopyUserInfoKey(err, RSErrorDescriptionKey))) result = RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("The operation couldn't be completed.(%R error %ld - %R)"), RSErrorGetDomain(err), RSErrorGetCode(err), reason); else result = RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("The operation couldn't be completed.(%R error %ld)"), RSErrorGetDomain(err), RSErrorGetCode(err)); } if (reason) RSRelease(reason); return result; }
static RSStringRef __RSFileManagerContentContextAppendPrefix(__RSFileManagerContentsContext* context, RSStringRef name) { if (context == nil || name == nil) return nil; else if (context->dirStack == nil) { return RSRetain(name); } return RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("%R/%R"), context->dirStack, name); }
static RSStringRef __RSDateClassDescription(RSTypeRef obj) { RSDateRef date = (RSDateRef)obj; RSGregorianDate gd = RSAbsoluteTimeGetGregorianDate(date->_time, nil); // %04d-%02d-%02d %02d:%02d:%02d.%03d RSStringRef description = RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("%04d-%02d-%02d %02d:%02d:%f"), gd.year,gd.month,gd.day, gd.hour,gd.minute,gd.second); return description; }
static RSStringRef __RSCalendarDescription(RSTypeRef obj) { RSCalendarRef calendar = (RSCalendarRef)obj; RSGregorianDate gd = RSAbsoluteTimeGetGregorianDate(RSAbsoluteTimeGetCurrent(), calendar->_tz); return RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("{identifier = '%R'\nCalendar : %04d-%02d-%02d %02d:%02d:%f (%R)"), calendar->_identifier, gd.year, gd.month, gd.day, gd.hour, gd.minute, gd.second, calendar->_tz); }
static RSStringRef __RSProcessInfoClassDescription(RSTypeRef rs) { RSStringRef description = RSStringCreateWithFormat(RSAllocatorDefault, RSSTR("RSProcessInfo %p"), rs); return description; }
static RSStringRef __RSTimerClassDescription(RSTypeRef rs) { RSTimerRef timer = (RSTimerRef)rs; return RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("%s <%p>"), __RSRuntimeGetClassNameWithInstance(timer), timer); }
static RSStringRef __RSTimeZoneClassDescription(RSTypeRef obj) { RSTimeZoneRef tz = (RSTimeZoneRef)obj; RSStringRef description = RSStringCreateWithFormat(RSAllocatorSystemDefault, RSSTR("%R - GMT : %5.0f"), __RSTimeZoneGetName(tz), RSTimeZoneGetSecondsFromGMT(tz, 0)); return description; }
static RSStringRef __RSFileMonitorClassDescription(RSTypeRef rs) { RSStringRef description = RSStringCreateWithFormat(RSAllocatorDefault, RSSTR("RSFileMonitor %p"), rs); return description; }
static RSStringRef __RSCoreUSBDeviceClassDescription(RSTypeRef rs) { RSStringRef description = RSStringCreateWithFormat(RSAllocatorDefault, RSSTR("RSCoreUSBDevice %p"), rs); return description; }