Sha256: fd7c0d529881322d0a2dd693fbb6ea632e62a1168644feffd98d0090f8866ce7

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

class NSString

  # @return [NSURL]
  def nsurl(baseURL=nil)
    @url ||= begin
      baseURL.nil? ? NSURL.alloc.initWithString(self) : NSURL.alloc.initWithString(self, relativeToURL: baseURL)
    end
  end

  # @return [NSURL]
  def fileurl(baseURL=nil)
    @fileurl ||= begin
      baseURL.nil? ? NSURL.fileURLWithPath(self) : NSURL.fileURLWithPath(self, relativeToURL: baseURL)
    end
  end

  def escape_url
    CFURLCreateStringByAddingPercentEscapes(
            nil,
            self,
            nil,
            "!*'();:@&=+$,/?%#[]",
            CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)
            )
  end

  def unescape_url
    self.stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
  end

  def remove_accents
    # removes diacritics by using a lossy conversion
    ascii = self.dataUsingEncoding(NSASCIIStringEncoding, allowLossyConversion: true)

    # turn it back into a string
    return NSString.alloc.initWithData(ascii, encoding: NSASCIIStringEncoding)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sugarcube-4.0.0 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.5.0 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.4.2 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.4.1 lib/cocoa/sugarcube-foundation/nsstring.rb