sugarcube 3.0.6 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a18aa0e7e38e8d512d750f820034f11692c7982
4
- data.tar.gz: b856bad2cebf2af6e45a0f64b15a3b9a7561368e
3
+ metadata.gz: c4433f242c29157de91a82193c803bf2bbe5b62c
4
+ data.tar.gz: c92a36e4e77fac55689af4795caf4b8e04393246
5
5
  SHA512:
6
- metadata.gz: 78bdc053c9b703528c9eeef6eb6cfe05e5df324456b802eb7f1d819ded480d8675e74c2b2c372af2ccb9002f9113c51785f2e88e8461b3e7c7a98081b39ed54a
7
- data.tar.gz: b85067e46bc080acef4094e15992d0209a75d3110e3ef228f0f5abf03029126013bf28f44f89b80dfd09e301664deb99c55d34cfe2643af219b12124b59e67a8
6
+ metadata.gz: a07af0dbc818c68088334d6d719edc4c578491c8284d2e9560398eb561ef9da38848b9de7b9e5f58ca0f374e029eaf9362ad3e0fdd33d8abd559e7c2386cf442
7
+ data.tar.gz: 976d1445e52230c5c73f840e8d406fea4c1523fec3137713eee6037c34d215c576c997f82aa14ab40a3c4f720decb404b34683f5e4feee69c15cb39f27595954
@@ -111,6 +111,28 @@ class NSAttributedString
111
111
  string
112
112
  end
113
113
 
114
+ def empty?
115
+ self.length == 0
116
+ end
117
+
118
+ def strip
119
+ # Trim leading whitespace and newlines.
120
+ charSet = NSCharacterSet.whitespaceAndNewlineCharacterSet
121
+ range = self.string.rangeOfCharacterFromSet(charSet)
122
+ while (range.length != 0 && range.location == 0)
123
+ self.replaceCharactersInRange(range, withString:"")
124
+ range = self.string.rangeOfCharacterFromSet(charSet)
125
+ end
126
+
127
+ # Trim trailing whitespace and newlines.
128
+ range = self.string.rangeOfCharacterFromSet(charSet, options:NSBackwardsSearch)
129
+ while (range.length != 0 && NSMaxRange(range) == self.length)
130
+ self.replaceCharactersInRange(range, withString:"")
131
+ range = self.string.rangeOfCharacterFromSet(charSet, options:NSBackwardsSearch)
132
+ end
133
+ self
134
+ end
135
+
114
136
  end
115
137
 
116
138
 
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '3.0.6'
2
+ Version = '3.0.7'
3
3
  end
@@ -37,6 +37,24 @@ describe 'NSAttributeString' do
37
37
  'test'.attrd.vertical_glyph_form(1).should.have_string_attributes({ NSVerticalGlyphFormAttributeName => 1 })
38
38
  end
39
39
 
40
+ it 'should have have `empty?`' do
41
+ 'test'.attrd.empty?.should == false
42
+ ''.attrd.empty?.should == true
43
+ end
44
+
45
+ it 'should have `strip`' do
46
+ 'test '.attrd.strip.should == 'test'.attrd
47
+ ' test '.attrd.strip.should == 'test'.attrd
48
+ ' test'.attrd.strip.should == 'test'.attrd
49
+ "\ntest".attrd.strip.should == 'test'.attrd
50
+ "\n test".attrd.strip.should == 'test'.attrd
51
+ "\n test \n".attrd.strip.should == 'test'.attrd
52
+ "\n test \n".attrd.strip.should == 'test'.attrd
53
+ "test ".attrd.strip.should == 'test'.attrd
54
+ "test\n ".attrd.strip.should == 'test'.attrd
55
+ " \n test".attrd.strip.should == 'test'.attrd
56
+ end
57
+
40
58
  end
41
59
 
42
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcube
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.6
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin T.A. Gray
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-01-14 00:00:00.000000000 Z
14
+ date: 2015-01-18 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: |
17
17
  == Description