Skip to content

Commit

Permalink
Remove monkeypatch to String
Browse files Browse the repository at this point in the history
String#bytesize is available now
  • Loading branch information
erickguan committed Mar 9, 2024
1 parent 0ff6306 commit 31c4ead
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 24 deletions.
1 change: 0 additions & 1 deletion lib/ffi-icu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def self.platform
end
end

require 'ffi-icu/core_ext/string'
require 'ffi-icu/lib'
require 'ffi-icu/lib/util'
require 'ffi-icu/uchar'
Expand Down
2 changes: 1 addition & 1 deletion lib/ffi-icu/break_iterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def text=(str)
@text = str

Lib.check_error do |err|
Lib.ubrk_setText(@iterator, UCharPointer.from_string(str), str.jlength, err)
Lib.ubrk_setText(@iterator, UCharPointer.from_string(str), str.bytesize, err)
end
end

Expand Down
20 changes: 10 additions & 10 deletions lib/ffi-icu/collation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ def locale
def compare(a, b)
Lib.ucol_strcoll(
@c,
UCharPointer.from_string(a), a.jlength,
UCharPointer.from_string(b), b.jlength
UCharPointer.from_string(a), a.bytesize,
UCharPointer.from_string(b), b.bytesize
)
end

def greater?(a, b)
Lib.ucol_greater(@c, UCharPointer.from_string(a), a.jlength,
UCharPointer.from_string(b), b.jlength)
Lib.ucol_greater(@c, UCharPointer.from_string(a), a.bytesize,
UCharPointer.from_string(b), b.bytesize)
end

def greater_or_equal?(a, b)
Lib.ucol_greaterOrEqual(@c, UCharPointer.from_string(a), a.jlength,
UCharPointer.from_string(b), b.jlength)
Lib.ucol_greaterOrEqual(@c, UCharPointer.from_string(a), a.bytesize,
UCharPointer.from_string(b), b.bytesize)
end

def equal?(*args)
Expand All @@ -96,8 +96,8 @@ def equal?(*args)

a, b = args

Lib.ucol_equal(@c, UCharPointer.from_string(a), a.jlength,
UCharPointer.from_string(b), b.jlength)
Lib.ucol_equal(@c, UCharPointer.from_string(a), a.bytesize,
UCharPointer.from_string(b), b.bytesize)
end

def collate(sortable)
Expand All @@ -116,9 +116,9 @@ def rules

def collation_key(string)
ptr = UCharPointer.from_string(string)
size = Lib.ucol_getSortKey(@c, ptr, string.jlength, nil, 0)
size = Lib.ucol_getSortKey(@c, ptr, string.bytesize, nil, 0)
buffer = FFI::MemoryPointer.new(:char, size)
Lib.ucol_getSortKey(@c, ptr, string.jlength, buffer, size)
Lib.ucol_getSortKey(@c, ptr, string.bytesize, buffer, size)
buffer.read_bytes(size - 1)
end

Expand Down
7 changes: 0 additions & 7 deletions lib/ffi-icu/core_ext/string.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/ffi-icu/normalization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module ICU
module Normalization
def self.normalize(input, mode = :default)
input_length = input.jlength
input_length = input.bytesize
needed_length = out_length = options = 0
in_ptr = UCharPointer.from_string(input)
out_ptr = UCharPointer.new(out_length)
Expand Down
4 changes: 2 additions & 2 deletions lib/ffi-icu/normalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(package_name = nil, name = 'nfc', mode = :decompose)
end

def normalize(input)
input_length = input.jlength
input_length = input.bytesize
in_ptr = UCharPointer.from_string(input)
needed_length = capacity = 0
out_ptr = UCharPointer.new(needed_length)
Expand All @@ -35,7 +35,7 @@ def normalize(input)
end

def is_normailzed?(input) # rubocop:disable Naming/PredicateName
input_length = input.jlength
input_length = input.bytesize
in_ptr = UCharPointer.from_string(input)

Lib.check_error do |error|
Expand Down
4 changes: 2 additions & 2 deletions lib/ffi-icu/transliteration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def initialize(id, rules = nil, direction = :forward)
rules_length = 0

if rules
rules_length = rules.jlength + 1
rules_length = rules.bytesize + 1
rules = UCharPointer.from_string(rules)
end

parse_error = Lib::UParseError.new
begin
Lib.check_error do |status|
ptr = Lib.utrans_openU(UCharPointer.from_string(id), id.jlength, direction, rules, rules_length,
ptr = Lib.utrans_openU(UCharPointer.from_string(id), id.bytesize, direction, rules, rules_length,
@parse_error, status)
@tr = FFI::AutoPointer.new(ptr, Lib.method(:utrans_close))
end
Expand Down

0 comments on commit 31c4ead

Please sign in to comment.