Пример #1
0
 static NSURL getURL(String fileName) {
   NSString unescapedStr;
   String lowercaseName = fileName.toLowerCase();
   if (lowercaseName.startsWith(PREFIX_HTTP)
       || lowercaseName.startsWith(PREFIX_HTTPS)
       || lowercaseName.startsWith(PREFIX_FILE)) {
     unescapedStr = NSString.stringWith("%#"); // $NON-NLS-1$
   } else {
     unescapedStr = NSString.stringWith("%"); // $NON-NLS-1$
   }
   NSString fullPath = NSString.stringWith(fileName);
   if (NSFileManager.defaultManager().fileExistsAtPath(fullPath)) {
     fullPath = NSURL.fileURLWithPath(fullPath).absoluteString();
   }
   long /*int*/ ptr =
       OS.CFURLCreateStringByAddingPercentEscapes(
           0, fullPath.id, unescapedStr.id, 0, OS.kCFStringEncodingUTF8);
   NSString escapedString = new NSString(ptr);
   NSURL url = NSURL.URLWithString(escapedString);
   OS.CFRelease(ptr);
   return url;
 }