Sha256: 9f8a1dbc62737fb467d28a25ce9f6dbf064776b967f3ed91d9659c1bb3f4c9c1

Contents?: true

Size: 855 Bytes

Versions: 62

Compression:

Stored size: 855 Bytes

Contents

class NSString

  # @return [NSURL]
  def nsurl
    @url ||= NSURL.alloc.initWithString(self)
  end

  # @return [NSURL]
  def fileurl
    @fileurl ||= NSURL.fileURLWithPath(self)
  end

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

  def unescape_url
    CFURLCreateStringByReplacingPercentEscapes(
            nil,
            self,
            ""
            )
  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

62 entries across 62 versions & 1 rubygems

Version Path
sugarcube-3.3.6 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.3.5 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.3.4 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.3.3 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.3.2 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.3.1 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.3.0 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.2.0 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.1.1 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.1.0 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.0.8 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.0.7 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.0.6 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.0.5 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.0.4 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.0.3 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.0.2 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.0.1 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-3.0.0 lib/cocoa/sugarcube-foundation/nsstring.rb
sugarcube-2.12.3 lib/cocoa/sugarcube-foundation/nsstring.rb