marcandre-backports 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -45,7 +45,7 @@ Compatible with Ruby 1.8 & 1.9.
45
45
  * +camelize+, +underscore+
46
46
  * +dasherize+, +demodulize+
47
47
  * +constantize+
48
- * +partition+
48
+ * +partition+, +rpartition+
49
49
  * Hash
50
50
  * <tt>Hash[[[:foo, :bar],[:hello, "world"]]] ==> {:foo => :bar, :hello => "world"}</tt> (see _note_)
51
51
  * +key+
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 3
4
- :patch: 0
4
+ :patch: 1
@@ -24,10 +24,9 @@ class String
24
24
 
25
25
  # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
26
26
  unless method_defined? :each_char
27
- VERY_BASIC_UTF8 = Regexp.new("[\x00-\x7f]|[\xc2-\xdf].|[\xe0-\xef]..|[\xf0-\xf4]...").freeze
28
27
  def each_char(&block)
29
28
  return to_enum(:each_char) unless block_given?
30
- scan(VERY_BASIC_UTF8, &block)
29
+ scan(/./, &block)
31
30
  end
32
31
  end
33
32
 
@@ -39,18 +38,35 @@ class String
39
38
  def partition_with_new_meaning(*args, &block)
40
39
  return partition_without_new_meaning(*args, &block) unless args.length == 1
41
40
  pattern = args.first
41
+
42
42
  i = index(pattern)
43
43
  return [self, "", ""] unless i
44
- unless pattern.instance_of? Regexp
45
- last = i+pattern.length
46
- [self[0...i], self[i...last], self[last...length]]
47
- else
44
+
45
+ if pattern.is_a? Regexp
48
46
  match = Regexp.last_match
49
47
  [match.pre_match, match[0], match.post_match]
48
+ else
49
+ last = i+pattern.length
50
+ [self[0...i], self[i...last], self[last...length]]
50
51
  end
51
52
  end
52
53
  alias_method_chain :partition, :new_meaning
53
54
  end
55
+
56
+ # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
57
+ def rpartition(pattern)
58
+ i = rindex(pattern)
59
+ return ["", "", self] unless i
60
+
61
+ if pattern.is_a? Regexp
62
+ match = Regexp.last_match
63
+ [match.pre_match, match[0], match.post_match]
64
+ else
65
+ last = i+pattern.length
66
+ [self[0...i], self[i...last], self[last...length]]
67
+ end
68
+ end unless method_defined? :rpartition
69
+
54
70
 
55
71
  # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
56
72
  def camelize(first_letter = :upper)
data/test/string_test.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ $KCODE = 'u' if RUBY_VERSION < '1.9'
2
3
  require 'test_helper'
3
4
 
4
5
  class StringTest < Test::Unit::TestCase
@@ -36,5 +37,13 @@ class StringTest < Test::Unit::TestCase
36
37
  assert_equal ["THX1138", "", ""], "THX1138".partition("99")
37
38
  end
38
39
  end
40
+
41
+ context "#rpartition" do
42
+ should "conform to doc" do
43
+ assert_equal ["THX1", "1", "38"], "THX1138".rpartition("1")
44
+ assert_equal ["THX1", "13", "8"], "THX1138".rpartition(/1\d/)
45
+ assert_equal ["", "", "THX1138"], "THX1138".rpartition("99")
46
+ end
47
+ end
39
48
  end
40
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marcandre-backports
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Marc-Andr\xC3\xA9 Lafortune"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-17 00:00:00 -07:00
12
+ date: 2009-04-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15