Sha256: 4786b4fc8c6ba4a59a55cf091b4c7b1bab74604240b2bbd77650f69db789f913

Contents?: true

Size: 746 Bytes

Versions: 16

Compression:

Stored size: 746 Bytes

Contents

class NSString

  # converts an NSString instance into a base64 string, using UTF8 encoding or
  # a user specified encoding.
  # @todo Support NSDataBase64EncodingOptions options - easy to add, but I want
  # to add specs, too, and a hash format (e.g. line_length: 64 =>
  # NSDataBase64Encoding64CharacterLineLength).
  def to_base64(enc=NSUTF8StringEncoding)
    encoded = self.dataUsingEncoding(enc)
    encoded.to_base64
  end

  # factory method to convert a base64 string into NSString, using UTF8 or a
  # user specified encoding.
  def self.from_base64(base64_str, enc=NSUTF8StringEncoding)
    data = NSData.from_base64(base64_str.dataUsingEncoding(NSASCIIStringEncoding))
    NSString.alloc.initWithData(data, encoding:enc)
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
sugarcube-4.0.0 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.5.0 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.4.2 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.4.1 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.4.0 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.3.7 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.3.6 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.3.5 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.3.4 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.3.3 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.3.2 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.3.1 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.3.0 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.2.0 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.1.1 lib/cocoa/sugarcube-base64/nsstring.rb
sugarcube-3.1.0 lib/cocoa/sugarcube-base64/nsstring.rb