Class: Kibuvits_krl171bt4_str

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/kibuvits_ruby_library_krl171bt4_.rb

Overview

Constant Summary collapse

@@cache =
Hash.new
@@mx_cache =
Mutex.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKibuvits_krl171bt4_str

Returns a new instance of Kibuvits_krl171bt4_str.



4612
4613
4614
4615
4616
4617
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 4612

def initialize
   # As of 2011 the valid range of Unicode points is U0000 to x2=U10FFFF
   # x2 = 16^5+15*16^3+15*16^2+15*16+15 = 1114111 ;
   @i_unicode_maximum_codepoint=1114111
   @b_kibuvits_krl171bt4_bootfile_run=(defined? KIBUVITS_krl171bt4_s_VERSION)
end

Instance Attribute Details

#i_unicode_maximum_codepointObject (readonly)

Returns the value of attribute i_unicode_maximum_codepoint.



4607
4608
4609
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 4607

def i_unicode_maximum_codepoint
  @i_unicode_maximum_codepoint
end

Class Method Details

.ar_bisect(input_string, separator_string, ar_output = Array.new(2,"")) ⇒ Object

ar_bisect



5382
5383
5384
5385
5386
5387
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5382

def Kibuvits_krl171bt4_str.ar_bisect(input_string, separator_string,
   ar_output=Array.new(2,""))
   ar=Kibuvits_krl171bt4_str.instance.ar_bisect(input_string,separator_string,
   ar_output)
   return ar
end

.ar_explode(s_haystack, s_needle) ⇒ Object

ar_explode



5626
5627
5628
5629
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5626

def Kibuvits_krl171bt4_str.ar_explode(s_haystack, s_needle)
   ar_out=Kibuvits_krl171bt4_str.instance.ar_explode s_haystack, s_needle
   return ar_out
end

.array2xseparated_list(ar, s_separator = ", ", s_left_brace = $kibuvits_krl171bt4_lc_emptystring, s_right_brace = $kibuvits_krl171bt4_lc_emptystring) ⇒ Object

array2xseparated_list



6047
6048
6049
6050
6051
6052
6053
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6047

def Kibuvits_krl171bt4_str.array2xseparated_list(ar,s_separator=", ",
   s_left_brace=$kibuvits_krl171bt4_lc_emptystring,
   s_right_brace=$kibuvits_krl171bt4_lc_emptystring)
   s_out=Kibuvits_krl171bt4_str.instance.array2xseparated_list(
   ar,s_separator,s_left_brace,s_right_brace)
   return s_out
end

.b_has_prefix(ar_or_s_prefix, s_haystack, ar_speedoptimization_prefixes_as_regexps = []) ⇒ Object



6188
6189
6190
6191
6192
6193
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6188

def Kibuvits_krl171bt4_str.b_has_prefix(ar_or_s_prefix, s_haystack,
   ar_speedoptimization_prefixes_as_regexps=[])
   b_out=Kibuvits_krl171bt4_str.instance.b_has_prefix(ar_or_s_prefix, s_haystack,
   ar_speedoptimization_prefixes_as_regexps)
   return b_out
end

.character_is_escapable(s_character, s_characters_that_are_excluded_from_the_list_of_escapables = "") ⇒ Object

character_is_escapable



5765
5766
5767
5768
5769
5770
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5765

def Kibuvits_krl171bt4_str.character_is_escapable(s_character,
   s_characters_that_are_excluded_from_the_list_of_escapables="")
   b=Kibuvits_krl171bt4_str.instance.character_is_escapable(s_character,
   s_characters_that_are_excluded_from_the_list_of_escapables)
   return b
end

.character_is_escaped(a_string, index_of_the_character) ⇒ Object

character_is_escaped



5918
5919
5920
5921
5922
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5918

def Kibuvits_krl171bt4_str.character_is_escaped(a_string,index_of_the_character)
   b_is_escaped=Kibuvits_krl171bt4_str.instance.character_is_escaped(a_string,
   index_of_the_character)
   return b_is_escaped
end

.clip_tail_by_str(s_haystack, s_needle) ⇒ Object

clip_tail_by_str



5951
5952
5953
5954
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5951

def Kibuvits_krl171bt4_str.clip_tail_by_str(s_haystack,s_needle)
   s_hay=Kibuvits_krl171bt4_str.instance.clip_tail_by_str(s_haystack,s_needle)
   return s_hay
end

.commaseparated_list_2_ar_t1(s_haystack, s_separator = ",") ⇒ Object



5665
5666
5667
5668
5669
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5665

def Kibuvits_krl171bt4_str.commaseparated_list_2_ar_t1(s_haystack,s_separator=",")
   ar_out=Kibuvits_krl171bt4_str.instance.commaseparated_list_2_ar_t1(
   s_haystack,s_separator)
   return ar_out
end

.commaseparated_list_2_ht_t1(s_haystack, s_separator = ",") ⇒ Object

commaseparated_list_2_ht_t1



5697
5698
5699
5700
5701
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5697

def Kibuvits_krl171bt4_str.commaseparated_list_2_ht_t1(s_haystack,s_separator=",")
   ht_out=Kibuvits_krl171bt4_str.instance.commaseparated_list_2_ht_t1(
   s_haystack,s_separator)
   return ht_out
end

.count_character_repetition(a_string, index_of_the_character) ⇒ Object

count_character_repetition



5887
5888
5889
5890
5891
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5887

def Kibuvits_krl171bt4_str.count_character_repetition(a_string,index_of_the_character)
   i_count=Kibuvits_krl171bt4_str.instance.count_character_repetition(a_string,
   index_of_the_character)
   return i_count
end

.datestring_for_fs_prefix(dt) ⇒ Object

datestring_for_fs_prefix



6476
6477
6478
6479
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6476

def Kibuvits_krl171bt4_str.datestring_for_fs_prefix(dt)
   s_out=Kibuvits_krl171bt4_str.instance.datestring_for_fs_prefix(dt)
   return s_out
end

.filter_array(condition_in_a_form_of_aregex_or_a_string, ar, b_condition_is_true_for_the_output_elements = true, b_output_is_a_hashtable = false) ⇒ Object

filter_array



6299
6300
6301
6302
6303
6304
6305
6306
6307
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6299

def Kibuvits_krl171bt4_str.filter_array(condition_in_a_form_of_aregex_or_a_string, ar,
   b_condition_is_true_for_the_output_elements=true,
   b_output_is_a_hashtable=false)
   ar_out=Kibuvits_krl171bt4_str.instance.filter_array(
   condition_in_a_form_of_aregex_or_a_string,
   ar, b_condition_is_true_for_the_output_elements,
   b_output_is_a_hashtable)
   return ar_out
end

.get_array_of_linebreaks(b_ok_to_be_immutable = false) ⇒ Object

get_array_of_linebreaks



5313
5314
5315
5316
5317
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5313

def Kibuvits_krl171bt4_str.get_array_of_linebreaks(b_ok_to_be_immutable=false)
   ar_linebreaks=Kibuvits_krl171bt4_str.instance.get_array_of_linebreaks(
   b_ok_to_be_immutable)
   return ar_linebreaks
end

.ht2str(ht, s_pair_prefix = "", s_separator = $kibuvits_krl171bt4_lc_linebreak) ⇒ Object

ht2str



6106
6107
6108
6109
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6106

def Kibuvits_krl171bt4_str.ht2str(ht, s_pair_prefix="",s_separator=$kibuvits_krl171bt4_lc_linebreak)
   s=Kibuvits_krl171bt4_str.instance.ht2str(ht,s_pair_prefix,s_separator)
   return s
end

.i_count_substrings(s_haystack, s_or_rgx_needle) ⇒ Object

i_count_substrings



5593
5594
5595
5596
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5593

def Kibuvits_krl171bt4_str.i_count_substrings(s_haystack,s_or_rgx_needle)
   i_out=Kibuvits_krl171bt4_str.instance.i_count_substrings s_haystack, s_or_rgx_needle
   return i_out
end

.index_is_outside_of_the_string(a_string, index) ⇒ Object

index_is_outside_of_the_string



5837
5838
5839
5840
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5837

def Kibuvits_krl171bt4_str.index_is_outside_of_the_string(a_string,index)
   b=Kibuvits_krl171bt4_str.instance.index_is_outside_of_the_string a_string, index
   return b
end

.normalise_linebreaks(s, substitution_string = $kibuvits_krl171bt4_lc_linebreak) ⇒ Object

normalise_linebreaks



5331
5332
5333
5334
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5331

def Kibuvits_krl171bt4_str.normalise_linebreaks(s,substitution_string=$kibuvits_krl171bt4_lc_linebreak)
   s_out=Kibuvits_krl171bt4_str.instance.normalise_linebreaks(s,substitution_string)
   return s_out
end

.normalize_s2ar_t1(s_or_ar_of_s, s_separator = ",") ⇒ Object



5734
5735
5736
5737
5738
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5734

def Kibuvits_krl171bt4_str.normalize_s2ar_t1(s_or_ar_of_s,s_separator=",")
   ar_out=Kibuvits_krl171bt4_str.instance.normalize_s2ar_t1(
   s_or_ar_of_s,s_separator)
   return ar_out
end

.pick_by_instance(s_start, s_end, s_haystack, msgcs = Kibuvits_krl171bt4_msgc_stack.new) ⇒ Object

pick_by_instance



4805
4806
4807
4808
4809
4810
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 4805

def Kibuvits_krl171bt4_str.pick_by_instance(s_start,s_end,s_haystack,
   msgcs=Kibuvits_krl171bt4_msgc_stack.new)
   s_hay,ht_out=Kibuvits_krl171bt4_str.instance.pick_by_instance(
   s_start,s_end,s_haystack,msgcs)
   return s_hay,ht_out
end

.ribboncut(s_needle, s_haystack) ⇒ Object

ribboncut



4992
4993
4994
4995
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 4992

def Kibuvits_krl171bt4_str.ribboncut(s_needle, s_haystack)
   ar_out=Kibuvits_krl171bt4_str.instance.ribboncut s_needle, s_haystack
   return ar_out
end

.s_batchreplace(ht_needles, s_haystack, b_needle_is_key = true) ⇒ Object

s_batchreplace



5136
5137
5138
5139
5140
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5136

def Kibuvits_krl171bt4_str.s_batchreplace(ht_needles, s_haystack, b_needle_is_key=true)
   s_out=Kibuvits_krl171bt4_str.instance.s_batchreplace(ht_needles,s_haystack,
   b_needle_is_key)
   return s_out
end

.s_escape_for_bash_t1(s_in) ⇒ Object

s_escape_for_bash_t1



5817
5818
5819
5820
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5817

def Kibuvits_krl171bt4_str.s_escape_for_bash_t1(s_in)
   s_out=Kibuvits_krl171bt4_str.instance.s_escape_for_bash_t1(s_in)
   return s_out
end

.s_escape_spaces_t1(s_in) ⇒ Object

s_escape_spaces_t1



5784
5785
5786
5787
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5784

def Kibuvits_krl171bt4_str.s_escape_spaces_t1(s_in)
   s_out=Kibuvits_krl171bt4_str.instance.s_escape_spaces_t1(s_in)
   return s_out
end

.s_get_substring_by_bounds(s_haystack, s_start, s_end, msgcs = Kibuvits_krl171bt4_msgc_stack.new) ⇒ Object



6567
6568
6569
6570
6571
6572
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6567

def Kibuvits_krl171bt4_str.s_get_substring_by_bounds(s_haystack,s_start,s_end,
   msgcs=Kibuvits_krl171bt4_msgc_stack.new)
   s_out=Kibuvits_krl171bt4_str.instance.s_get_substring_by_bounds(
   s_haystack,s_start,s_end,msgcs)
   return s_out
end

.s_i2unicode(i_codepoint) ⇒ Object

s_i2unicode



6501
6502
6503
6504
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6501

def Kibuvits_krl171bt4_str.s_i2unicode(i_codepoint)
   s_out=Kibuvits_krl171bt4_str.instance.s_i2unicode(i_codepoint)
   return s_out
end

.s_paintrollerreplace(s_or_rgx_needle_id_est_stripe_placeholder, s_or_ar_of_substitution_strings_or_a_function_ie_stripes, s_haystack) ⇒ Object

s_paintrollerreplace



5258
5259
5260
5261
5262
5263
5264
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5258

def Kibuvits_krl171bt4_str.s_paintrollerreplace(s_or_rgx_needle_id_est_stripe_placeholder,
   s_or_ar_of_substitution_strings_or_a_function_ie_stripes, s_haystack)
   s_out=Kibuvits_krl171bt4_str.instance.s_paintrollerreplace(
   s_or_rgx_needle_id_est_stripe_placeholder,
   s_or_ar_of_substitution_strings_or_a_function_ie_stripes, s_haystack)
   return s_out
end

.s_s_bisect_by_header_t1(s_in, msgcs) ⇒ Object

s_s_bisect_by_header_t1



5549
5550
5551
5552
5553
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5549

def Kibuvits_krl171bt4_str.s_s_bisect_by_header_t1(s_in,msgcs)
   s_left,s_right=Kibuvits_krl171bt4_str.instance.s_s_bisect_by_header_t1(
   s_in,msgcs)
   return s_left,s_right
end

.s_to_s_with_assured_amount_of_digits_t1(i_minimum_amount_of_digits, i_positive_whole_number) ⇒ Object

s_to_s_with_assured_amount_of_digits_t1



6597
6598
6599
6600
6601
6602
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6597

def Kibuvits_krl171bt4_str.s_to_s_with_assured_amount_of_digits_t1(
   i_minimum_amount_of_digits, i_positive_whole_number)
   s_out=Kibuvits_krl171bt4_str.instance.s_to_s_with_assured_amount_of_digits_t1(
   i_minimum_amount_of_digits, i_positive_whole_number)
   return s_out
end

.snatch_n_times_t1(s_haystack, s_separator, n) ⇒ Object

snatch_n_times_t1



5459
5460
5461
5462
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5459

def Kibuvits_krl171bt4_str.snatch_n_times_t1(s_haystack, s_separator,n)
   ar_out=Kibuvits_krl171bt4_str.instance.snatch_n_times_t1(s_haystack, s_separator,n)
   return ar_out
end

.sort_by_length(array_of_strings, longest_strings_first = true) ⇒ Object

It modifies the input array.



4923
4924
4925
4926
4927
4928
4929
4930
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 4923

def Kibuvits_krl171bt4_str.sort_by_length(array_of_strings, longest_strings_first=true)
   if longest_strings_first
      array_of_strings.sort!{|a,b| b.length<=>a.length}
   else
      array_of_strings.sort!{|a,b| a.length<=>b.length}
   end # if
   return nil
end

.str2strliteral(s_in, s_quotation_mark = $kibuvits_krl171bt4_lc_doublequote, b_escape_quotation_marks = true, b_escape_backslashes = true, s_concatenation_mark = "+") ⇒ Object

str2strliteral



6424
6425
6426
6427
6428
6429
6430
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6424

def Kibuvits_krl171bt4_str.str2strliteral(s_in,s_quotation_mark=$kibuvits_krl171bt4_lc_doublequote,
   b_escape_quotation_marks=true, b_escape_backslashes=true,
   s_concatenation_mark="+")
   s_out=Kibuvits_krl171bt4_str.instance.str2strliteral(s_in,s_quotation_mark,
   b_escape_quotation_marks,b_escape_backslashes,s_concatenation_mark)
   return s_out
end

.str_contains_spacestabslinebreaks(s_candidate) ⇒ Object

str_contains_spacestabslinebreaks



6450
6451
6452
6453
6454
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6450

def Kibuvits_krl171bt4_str.str_contains_spacestabslinebreaks(s_candidate)
   b_out=Kibuvits_krl171bt4_str.instance.str_contains_spacestabslinebreaks(
   s_candidate)
   return b_out
end

.surround_lines(s_line_prefix, s_text, s_line_suffix, b_s_text_has_been_normalized_to_use_unix_line_breaks = false) ⇒ Object

surround_lines



6227
6228
6229
6230
6231
6232
6233
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6227

def Kibuvits_krl171bt4_str.surround_lines(s_line_prefix,s_text,s_line_suffix,
   b_s_text_has_been_normalized_to_use_unix_line_breaks=false)
   s_out=Kibuvits_krl171bt4_str.instance.surround_lines(
   s_line_prefix,s_text,s_line_suffix,
   b_s_text_has_been_normalized_to_use_unix_line_breaks)
   return s_out
end

.trim(s_string) ⇒ Object

trim



5970
5971
5972
5973
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5970

def Kibuvits_krl171bt4_str.trim(s_string)
   s_out=Kibuvits_krl171bt4_str.instance.trim s_string
   return s_out
end

.verify_noninclusion(array_of_strings) ⇒ Object

verify_noninclusion



4699
4700
4701
4702
4703
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 4699

def Kibuvits_krl171bt4_str.verify_noninclusion(array_of_strings)
   b_inclusion_present,msg=Kibuvits_krl171bt4_str.instance.verify_noninclusion(
   array_of_strings)
   return b_inclusion_present,msg
end

.verify_s_is_within_domain(s_to_test, s_or_ar_of_domain_elements, msgcs, s_action_on_verification_failure = "note_in_msgcs", s_language_to_use_for_printing = $kibuvits_krl171bt4_lc_English) ⇒ Object

verify_s_is_within_domain



6385
6386
6387
6388
6389
6390
6391
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6385

def Kibuvits_krl171bt4_str.verify_s_is_within_domain(s_to_test,s_or_ar_of_domain_elements,
   msgcs,s_action_on_verification_failure="note_in_msgcs",
   s_language_to_use_for_printing=$kibuvits_krl171bt4_lc_English)
   Kibuvits_krl171bt4_str.instance.verify_s_is_within_domain(
   s_to_test,s_or_ar_of_domain_elements, msgcs,
   s_action_on_verification_failure,s_language_to_use_for_printing)
end

.wholenumber_ASCII_2_whonenumber_Unicode(i_ascii) ⇒ Object

wholenumber_ASCII_2_whonenumber_Unicode



4914
4915
4916
4917
4918
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 4914

def Kibuvits_krl171bt4_str.wholenumber_ASCII_2_whonenumber_Unicode(i_ascii)
   b_failure, i_out, msg=Kibuvits_krl171bt4_str.instance.wholenumber_ASCII_2_whonenumber_Unicode(
   i_ascii)
   return b_failure, i_out, msg
end

Instance Method Details

#ar_bisect(input_string, separator_string, ar_output = Array.new(2,$kibuvits_krl171bt4_lc_emptystring)) ⇒ Object

It returns an array of 2 elements. If the separator is not found, the array==input_string and array==“”.

The ar_output is for array instance reuse and is expected to increase speed a tiny bit at “snatching”.



5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5343

def ar_bisect(input_string,separator_string,ar_output=Array.new(2,$kibuvits_krl171bt4_lc_emptystring))
   # If one updates this code, then one should also copy-paste
   # an updated version of this method to the the ProgFTE implementation.
   # The idea behind such an arrangement is that the ProgFTE implementation
   # is not allowed to have any dependencies other than the library booting code.
   #
   # TODO: Optimize it to use smaller temporary string instances. For example,
   #       in stead of "a|b|c|d"->("a", "b|c|d"->("b","c|d"->("c","d")))
   #       one should: "a|b|c|d"->("a|b"->("a","d"),"c|d"->("c","d"))
   i_separator_stringlen=separator_string.length
   if i_separator_stringlen==0
      exc=Exception.new("separator_string==\"\"")
      if @b_kibuvits_krl171bt4_bootfile_run
         kibuvits_krl171bt4_throw(exc)
      else
         raise(exc)
      end # if
   end # if
   ar=ar_output
   i=input_string.index(separator_string)
   if(i==nil)
      ar[0]=input_string
      ar[1]=$kibuvits_krl171bt4_lc_emptystring
      return ar;
   end # if
   if i==0
      ar[0]=$kibuvits_krl171bt4_lc_emptystring
   else
      ar[0]=input_string[0..(i-1)]
   end # if
   i_input_stringlen=input_string.length
   if (i+i_separator_stringlen)==i_input_stringlen
      ar[1]=$kibuvits_krl171bt4_lc_emptystring
   else
      ar[1]=input_string[(i+i_separator_stringlen)..(-1)]
   end # if
   return ar
end

#ar_explode(s_haystack, s_needle) ⇒ Object

It mimics the PHP explode function, but it’s not a one to one copy of it. Practically, it converts the s_haystack to an array and uses the s_needle as a separator at repetitive bisection.



5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5604

def ar_explode(s_haystack, s_needle)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_haystack
      kibuvits_krl171bt4_typecheck bn, String, s_needle
   end # if
   i_s_haystack=s_haystack.length
   return [""] if i_s_haystack==0
   i_s_needlelen=s_needle.length
   if i_s_needlelen==0
      ar_out=Array.new
      i_s_haystack.times{|i| ar_out<<s_haystack[i..i]}
      return ar_out
   end # if
   return [s_haystack] if i_s_haystack<i_s_needlelen
   ar_out=Array.new
   i_needlecount=Kibuvits_krl171bt4_str.i_count_substrings(s_haystack, s_needle)
   s_hay=s_haystack+s_needle
   ar_out=Kibuvits_krl171bt4_str.snatch_n_times_t1(s_hay,s_needle,(i_needlecount+1))
   return ar_out
end

#array2xseparated_list(ar, s_separator = ", ", s_left_brace = $kibuvits_krl171bt4_lc_emptystring, s_right_brace = $kibuvits_krl171bt4_lc_emptystring) ⇒ Object

The point behind this method is that if the array has zero elements, the output is an empty string, but there should not be any commas after the very last element.

A member of the reverse of this group of methods is

commaseparated_list_2_ar_t1(...)


5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5984

def array2xseparated_list(ar,s_separator=", ",
   s_left_brace=$kibuvits_krl171bt4_lc_emptystring,
   s_right_brace=$kibuvits_krl171bt4_lc_emptystring)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, Array, ar
      kibuvits_krl171bt4_typecheck bn, String, s_separator
      kibuvits_krl171bt4_typecheck bn, String, s_left_brace
      kibuvits_krl171bt4_typecheck bn, String, s_right_brace
   end # if
   s_out="" # not $kibuvits_krl171bt4_lc_emptystring to allow the << operator to work later
   return s_out if ar.length==0
   b_at_least_one_element_is_already_in_the_list=false
   ar_s=Array.new
   if s_left_brace==$kibuvits_krl171bt4_lc_emptystring
      if s_right_brace==$kibuvits_krl171bt4_lc_emptystring
         ar.each do |s_x|
            if b_at_least_one_element_is_already_in_the_list
               ar_s<<s_separator
            else
               b_at_least_one_element_is_already_in_the_list=true
            end # if
            ar_s<<s_x.to_s
         end # end
      else # only right bracket is present
         ar.each do |s_x|
            if b_at_least_one_element_is_already_in_the_list
               ar_s<<s_separator
            else
               b_at_least_one_element_is_already_in_the_list=true
            end # if
            ar_s<<s_x.to_s
            ar_s<<s_right_brace
         end # end
      end # if
   else
      if s_right_brace==$kibuvits_krl171bt4_lc_emptystring
         ar.each do |s_x|
            if b_at_least_one_element_is_already_in_the_list
               ar_s<<s_separator
            else
               b_at_least_one_element_is_already_in_the_list=true
            end # if
            ar_s<<s_left_brace
            ar_s<<s_x.to_s
         end # end
      else # both braces are present
         ar.each do |s_x|
            if b_at_least_one_element_is_already_in_the_list
               ar_s<<s_separator
            else
               b_at_least_one_element_is_already_in_the_list=true
            end # if
            ar_s<<s_left_brace
            ar_s<<s_x.to_s
            ar_s<<s_right_brace
         end # end
      end # if
   end # if
   s_out=kibuvits_krl171bt4_s_concat_array_of_strings(ar_s)
   return s_out
end

#b_has_prefix(ar_or_s_prefix, s_haystack, ar_speedoptimization_prefixes_as_regexps = []) ⇒ Object

If the ar_speedoptimization_prefixes_as_regexps.class==Array and ar_speedoptimization_prefixes_as_regexps.size==0 and ar_or_s_prefix!=“” and ar_or_s_prefix.size!=0 then the ar_speedoptimization_prefixes_as_regexps is filled with regular expression objects that have been generated from the ar_or_s_prefix.

If the ar_speedoptimization_prefixes_as_regexps.class==Array and 0 < ar_speedoptimization_prefixes_as_regexps.size then the content of the ar_or_s_prefix is ignored.

Empty string is considered to be the prefix of all strings, including an empty string.

The elements of the ar_speedoptimization_prefixes_as_regexps must not be created or edited outside of this function.



6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6133

def b_has_prefix(ar_or_s_prefix, s_haystack,
   ar_speedoptimization_prefixes_as_regexps=[])
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, [String,Array], ar_or_s_prefix
      kibuvits_krl171bt4_typecheck bn, String, s_haystack
      kibuvits_krl171bt4_typecheck bn, Array, ar_speedoptimization_prefixes_as_regexps

      if ar_or_s_prefix.class==Array
         kibuvits_krl171bt4_typecheck_ar_content(bn,String,
         ar_or_s_prefix,
         "\nGUID='a2b82afa-0117-4c81-b200-c13290a118e7'\n\n")
      end # if
      kibuvits_krl171bt4_typecheck_ar_content(bn,Regexp,
      ar_speedoptimization_prefixes_as_regexps,
      "\nGUID='8c5703c4-2fdf-4005-a2ef-c13290a118e7'\n\n")
   end # if
   ar_rgx=ar_speedoptimization_prefixes_as_regexps
   if ar_rgx.size==0
      rgx=nil
      ar_prefixes=Kibuvits_krl171bt4_ix.normalize2array(ar_or_s_prefix).uniq
      ar_prefixes.each do |s_prefix|
         if s_prefix==$kibuvits_krl171bt4_lc_emptystring
            # There is no point of studying the
            # other prefixes, if the empty string
            # is considered to be a prefix of all strings.
            ar_rgx=[/^/]
            break
         end # if
         rgx=Regexp.new($kibuvits_krl171bt4_lc_powersign+s_prefix)
         ar_rgx<<rgx
      end # loop
   end # if
   b_out=false
   if ar_rgx.size==1
      if ar_rgx[0].to_s==/^/.to_s
         # An empty string is considered to be a prefix of all strings.
         b_out=true
         return b_out
      end # if
   end # if
   s_0=nil
   i_len_s_haystack=s_haystack.length
   return b_out if i_len_s_haystack==0 # speed hack
   ar_rgx.each do |rgx|
      s_0=s_haystack.sub(rgx,$kibuvits_krl171bt4_lc_emptystring)
      if s_0.length!=i_len_s_haystack
         b_out=true
         break
      end # if
   end # loop
   return b_out
end

#character_is_escapable(s_character, s_characters_that_are_excluded_from_the_list_of_escapables = "") ⇒ Object



5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5744

def character_is_escapable(s_character,
   s_characters_that_are_excluded_from_the_list_of_escapables="")
   bn=binding()
   if KIBUVITS_krl171bt4_b_DEBUG
      kibuvits_krl171bt4_typecheck bn, String, s_character
   end # if
   if s_character.length!=1
      kibuvits_krl171bt4_throw "s_character==\""+s_character+"\", "+"s_character.length!=1"
   end # if
   s_xc=s_characters_that_are_excluded_from_the_list_of_escapables
   if KIBUVITS_krl171bt4_b_DEBUG
      kibuvits_krl171bt4_typecheck bn, String, s_xc
   end # if
   b=false
   if !s_xc.include? s_character
      s_escapables="\"'\n\r\t\\"
      b=s_escapables.include? s_character
   end # if
   return b
end

#character_is_escaped(a_string, index_of_the_character) ⇒ Object

The idea is that in “n” and “\n” the n is escaped, but in “\n” and “\\\n” the n is not escaped.



5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5898

def character_is_escaped(a_string,index_of_the_character)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, a_string
      kibuvits_krl171bt4_typecheck bn, Fixnum, index_of_the_character
   end # if
   i_ix=index_of_the_character
   if Kibuvits_krl171bt4_str.index_is_outside_of_the_string(a_string,i_ix)
      kibuvits_krl171bt4_throw "index_of_the_character=="+i_ix.to_s+" is outside of "+
      "string a_string==\""+a_string+"\"."
   end # if
   return false if i_ix==0
   i_prfx=i_ix-1
   return false if a_string[i_prfx..i_prfx]!="\\"
   s_az=(a_string[0..i_prfx]).reverse
   i_count=Kibuvits_krl171bt4_str.count_character_repetition(s_az, 0)
   b_is_escaped=((i_count%2)==1)
   return b_is_escaped
end

#clip_tail_by_str(s_haystack, s_needle) ⇒ Object



5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5927

def clip_tail_by_str(s_haystack,s_needle)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_haystack
      kibuvits_krl171bt4_typecheck bn, String, s_needle
   end # if
   i_sh_len=s_haystack.length
   i_sn_len=s_needle.length
   s_hay=s_haystack+$kibuvits_krl171bt4_lc_emptystring # to return a different instance
   return s_hay if (i_sh_len<i_sn_len)||(i_sn_len==0)
   if i_sh_len==i_sn_len
      if s_hay==s_needle
         return $kibuvits_krl171bt4_lc_emptystring
      else
         # For speed only. There's no point of re-comparing.
         return s_hay
      end # if
   end # if
   if s_hay[(i_sh_len-i_sn_len)..(-1)]==s_needle
      return s_hay[0..(i_sh_len-i_sn_len-1)]
   end # if
   return s_hay
end

#commaseparated_list_2_ar_t1(s_haystack, s_separator = ",") ⇒ Object

Part of the same group of methods with

commaseparated_list_2_ht_t1(...)

A member of the reverse of this group of methods is

array2xseparated_list(...)

A thing to remember is that some text needs more advanced parsing: “elephant, giraffe” , “horse”, “cow”



5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5645

def commaseparated_list_2_ar_t1(s_haystack,s_separator=",")
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_haystack
      kibuvits_krl171bt4_typecheck bn, String, s_separator
   end # if
   ar=ar_explode(s_haystack,s_separator)
   ar_out=Array.new
   i_ar_len=ar.size
   s_piece=nil
   s=nil
   i_ar_len.times do |ix|
      s_piece=ar[ix]
      s=trim(s_piece)
      ar_out<<s if 0<s.length
   end # loop
   return ar_out
end

#commaseparated_list_2_ht_t1(s_haystack, s_separator = ",") ⇒ Object

Part of the same group of methods with

commaseparated_list_2_ar_t1(...)

A member of the reverse of this group of methods is

array2xseparated_list(...)


5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5680

def commaseparated_list_2_ht_t1(s_haystack,s_separator=",")
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_haystack
      kibuvits_krl171bt4_typecheck bn, String, s_separator
   end # if
   ar=commaseparated_list_2_ar_t1(s_haystack,s_separator)
   ht_out=Hash.new
   i_ar_len=ar.size
   s_piece=nil
   i_ar_len.times do |ix|
      s_piece=ar[ix]
      ht_out[s_piece]=ix
   end # loop
   return ht_out
end

#count_character_repetition(a_string, index_of_the_character) ⇒ Object

Explanation by an example: count_character_repetition(“aXXaXXX”,1)==2

0123456

count_character_repetition(“aXXaXXX”,4)==3

0123456

count_character_repetition(“aXXaXXX”,3)==1

0123456

count_character_repetition(“aXXaXXX”,6)==1

0123456


5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5854

def count_character_repetition(a_string,index_of_the_character)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, a_string
      kibuvits_krl171bt4_typecheck bn, Fixnum, index_of_the_character
   end # if
   i_ix=index_of_the_character
   i_smax=a_string.length-1
   if Kibuvits_krl171bt4_str.index_is_outside_of_the_string(a_string,i_ix)
      kibuvits_krl171bt4_throw "index_of_the_character=="+i_ix.to_s+" is outside of "+
      "string a_string==\""+a_string+"\".\n"+
      "GUID='79ad771e-27fe-47c6-8510-c13290a118e7'\n\n"
   end # if
   s_char=a_string[i_ix..i_ix]
   i_count=0
   if Kibuvits_krl171bt4_str.character_is_escapable(s_char)
      i_iix=i_ix
      while i_iix<=i_smax
         break if a_string[i_iix..i_iix]!=s_char
         i_iix=i_iix+1
      end # loop
      i_count=i_iix-i_ix
   else
      s_hay=a_string[i_ix..(-1)]
      rg=Regexp.new("["+s_char+"]+")
      md=rg.match(s_hay)
      kibuvits_krl171bt4_throw "md==nil" if md==nil
      i_count=md[0].length
   end # if
   kibuvits_krl171bt4_throw "i_count=="+i_count.to_s+"<1" if i_count<1
   return i_count
end

#datestring_for_fs_prefix(dt) ⇒ Object



6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6459

def datestring_for_fs_prefix(dt)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, Time, dt
   end # if
   s_out=$kibuvits_krl171bt4_lc_emptystring
   i=dt.month
   s=i.to_s
   s="0"+s if i<10
   s_out=(dt.year.to_s+$kibuvits_krl171bt4_lc_underscore)+(s+$kibuvits_krl171bt4_lc_underscore)
   i=dt.day
   s=i.to_s
   s="0"+s if i<10
   s_out=s_out+s
   return s_out
end

#filter_array(condition_in_a_form_of_aregex_or_a_string, ar, b_condition_is_true_for_the_output_elements = true, b_output_is_a_hashtable = false) ⇒ Object

The elements of the array “ar” do not have to be strings, because prior to comparison their to_s methods are called. If the output array contains anything at all, the output array will consists of the references to the original array elements.

If b_output_is_a_hashtable==false, the output is an array. If b_output_is_a_hashtable==true, the output is a hashtable, where the output is in the role of keys. The values are set to 42.



6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6247

def filter_array(condition_in_a_form_of_aregex_or_a_string, ar,
   b_condition_is_true_for_the_output_elements=true,
   b_output_is_a_hashtable=false)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, [String,Regexp], condition_in_a_form_of_aregex_or_a_string
      kibuvits_krl171bt4_typecheck bn, Array, ar
      kibuvits_krl171bt4_typecheck bn, [TrueClass,FalseClass], b_condition_is_true_for_the_output_elements
      kibuvits_krl171bt4_typecheck bn, [TrueClass,FalseClass], b_output_is_a_hashtable
   end # if
   md=nil
   rgx=condition_in_a_form_of_aregex_or_a_string
   if condition_in_a_form_of_aregex_or_a_string.class==String
      rgx=Regexp.compile(condition_in_a_form_of_aregex_or_a_string)
   end # if
   x_out=nil
   if b_output_is_a_hashtable # The branches are to keep if out of the loop.
      ht_out=Hash.new
      i_42=42 # One Fixnum instance per whole ht_out.
      if b_condition_is_true_for_the_output_elements
         ar.each do |x|
            ht_out[x]=i_42 if rgx.match(x.to_s)!=nil
         end # loop
      else
         ar.each do |x|
            ht_out[x]=i_42 if rgx.match(x.to_s)==nil
         end # loop
      end # if
      x_out=ht_out
   else
      ar_out=Array.new
      i_arlen=ar.length # To guarantee the order, which is useful for testing.
      if b_condition_is_true_for_the_output_elements
         i_arlen.times do |i|
            x=ar[i]
            if rgx.match(x.to_s)!=nil
               ar_out<<x
            end # if
         end # loop
      else
         i_arlen.times do |i|
            x=ar[i]
            if rgx.match(x.to_s)==nil
               ar_out<<x
            end # if
         end # loop
      end # if
      x_out=ar_out
   end # if b_output_is_a_hashtable
   return x_out
end

#get_array_of_linebreaks(b_ok_to_be_immutable = false) ⇒ Object

A citation from en.wikipedia.org/wiki/Newline (visit date: January 2010)

The Unicode standard defines a large number of characters that conforming applications should recognize as line terminators: [2]

LF:    Line Feed, U+000A
CR:    Carriage Return, U+000D
CR+LF: CR (U+000D) followed by LF (U+000A)
NEL:   Next Line, U+0085
FF:    Form Feed, U+000C
LS:    Line Separator, U+2028
PS:    Paragraph Separator, U+2029

The ruby 1.8 string operations do not support Unicode code-points properly (blog.grayproductions.net/articles/bytes_and_characters_in_ruby_18 ), TODO: this method is subject to completion after one can fully move to ruby 1.9



5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5288

def get_array_of_linebreaks(b_ok_to_be_immutable=false)
   if (@@cache.has_key? 'ar_linebreaks')
      ar_linebreaks_immutable=@@cache['ar_linebreaks']
      ar_linebreaks=ar_linebreaks_immutable
      if !b_ok_to_be_immutable
         ar_linebreaks=Array.new
         ar_linebreaks_immutable.each{|x| ar_linebreaks<<""+x}
      end # if
      return ar_linebreaks
   end # if
   @@mx_cache.synchronize do
      break if (@@cache.has_key? 'ar_linebreaks')
      ar_linebreaks_immutable=["\r\n","\n","\r"]
      ar_linebreaks_immutable.freeze
      @@cache['ar_linebreaks']=ar_linebreaks_immutable
   end # synchronize
   ar_linebreaks_immutable=@@cache['ar_linebreaks']
   ar_linebreaks=ar_linebreaks_immutable
   if !b_ok_to_be_immutable
      ar_linebreaks=Array.new
      ar_linebreaks_immutable.each{|x| ar_linebreaks<<""+x}
   end # if
   return ar_linebreaks
end

#ht2str(ht, s_pair_prefix = "", s_separator = $kibuvits_krl171bt4_lc_linebreak) ⇒ Object

Returns a string. In many, but not all, cases it doesn’t stop the infinite recursion, if there’s a condition that a hashtable is an element of oneself or an element of one of its elements.

This method is useful for generating console output during debugging.



6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6064

def ht2str(ht, s_pair_prefix="",s_separator=$kibuvits_krl171bt4_lc_linebreak)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, Hash, ht
      kibuvits_krl171bt4_typecheck bn, String, s_separator
   end # if
   s_out=""
   i_max_len=0
   i=nil
   ht.each_key do |a_key|
      i=a_key.to_s.length
      i_max_len=i if i_max_len<i
   end # loop
   s_x=""
   cl=nil
   b_first_line=true
   s_child_prefix=s_pair_prefix+"  "
   s_key=nil
   ht.each_pair do |a_key,a_value|
      s_out=s_out+s_separator if !b_first_line
      b_first_line=false
      cl=a_value.class.to_s
      s_key=a_key.to_s
      s_key=(" "*(i_max_len-s_key.length))+s_key
      case cl
      when "Array"
         s_x="["+Kibuvits_krl171bt4_str.array2xseparated_list(a_value)+"]"
         s_out=s_out+s_pair_prefix+s_key+"="+s_x
      when "Hash"
         s_x=Kibuvits_krl171bt4_str.ht2str(a_value,
         " "*(i_max_len+1)+s_child_prefix)
         s_out=s_out+s_key+"=Hash\n"+s_x
      when "NilClass"
         s_out=s_out+s_pair_prefix+s_key+"=nil"
      else
         s_x=a_value.to_s
         s_out=s_out+s_pair_prefix+s_key+"="+s_x
      end
   end # loop
   return s_out
end

#i_count_substrings(s_haystack, s_or_rgx_needle) ⇒ Object



5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5558

def i_count_substrings(s_haystack,s_or_rgx_needle)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_haystack
      kibuvits_krl171bt4_typecheck bn, [String,Regexp], s_or_rgx_needle
   end # if
   #----
   i_out=nil
   if s_or_rgx_needle.class==String
      i_s_or_rgx_needlelen=s_or_rgx_needle.length
      if i_s_or_rgx_needlelen==0
         kibuvits_krl171bt4_throw("s_or_rgx_needle.class==String is OK, but \n"+
         "s_or_rgx_needle.length==0 is not acceptable, because \n"+
         "every string contains an infinite number of emptystrings.\n"+
         "GUID='16ae0125-2acc-4a7f-8c60-c13290a118e7'\n\n")
      end # if
      # This if-branch is probably redundant, because
      # the onel-liner at the else part does a pretty
      # good job, but the solution in this branch
      # is more straightforward and therefore seems
      # to be more robust, because there's no need
      # to make an thoroughly untested/maybe-properly-untestable
      # assumption about the String.scan(...).
      i_s_haystack=s_haystack.length
      i=s_haystack.gsub(s_or_rgx_needle,$kibuvits_krl171bt4_lc_emptystring).length
      return 0 if i==i_s_haystack
      i_out=(i_s_haystack-i)/i_s_or_rgx_needlelen # It all stays in Fixnum domain.
   else # s_or_rgx_needle.class==Regexp
      # Credits go to the Jon Kern at
      # http://stackoverflow.com/questions/5305638/stringcount-options
      i_out=s_haystack.scan(s_or_rgx_needle).count
   end # if
   return i_out
end

#index_is_outside_of_the_string(a_string, index) ⇒ Object



5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5825

def index_is_outside_of_the_string(a_string,index)
   # TODO: Move this method to Kibuvits_krl171bt4_ix and make it also work
   # with arrays and alike.
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, a_string
      kibuvits_krl171bt4_typecheck bn, Fixnum, index
   end # if
   b=((index<0)||(a_string.length-1)<index)
   return b
end

#normalise_linebreaks(s, substitution_string = $kibuvits_krl171bt4_lc_linebreak) ⇒ Object




5321
5322
5323
5324
5325
5326
5327
5328
5329
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5321

def normalise_linebreaks(s,substitution_string=$kibuvits_krl171bt4_lc_linebreak)
   s_subst=substitution_string
   ar_special_cases=Kibuvits_krl171bt4_str.get_array_of_linebreaks true
   ht_needles=Hash.new
   ht_needles[s_subst]=ar_special_cases
   s_hay=s
   s_out=Kibuvits_krl171bt4_str.s_batchreplace ht_needles, s_hay, false
   return s_out
end

#normalize_s2ar_t1(s_or_ar_of_s, s_separator = ",") ⇒ Object




5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5706

def normalize_s2ar_t1(s_or_ar_of_s,s_separator=",")
   cl_0=s_or_ar_of_s.class
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, [String,Array], s_or_ar_of_s
      kibuvits_krl171bt4_typecheck bn, String, s_separator
      if cl_0==Array
         kibuvits_krl171bt4_assert_ar_elements_typecheck_if_is_array(bn,String,
         s_or_ar_of_s,"GUID=='32dfe110-b332-4d46-b140-c13290a118e7'")
      end # if
   end # if
   ar_out=nil
   if cl_0==String
      ar_out=Kibuvits_krl171bt4_str.commaseparated_list_2_ar_t1(
      s_or_ar_of_s,s_separator)
   else
      if cl_0==Array
         ar_out=s_or_ar_of_s
      else
         kibuvits_krl171bt4_throw("s_or_ar_of_s.class=="+cl_0.to_s+
         ",\nbut it is expected to be either String or Array.\n"+
         "GUID='e154bd3e-738e-4d4b-9430-c13290a118e7'\n\n")
      end # if
   end # if
   return ar_out
end

#pick_by_instance(s_start, s_end, s_haystack, msgcs = Kibuvits_krl171bt4_msgc_stack.new) ⇒ Object

Replaces each block that starts with s_start and ends with s_end, with a Globally Unique Identifier (GUID). It does not guarantee that the text before and after the s_start and s_end won’t “blend in” with the GUID like “para”+“dise”+“diseases”=“paradise”+“dise+”ases“ or ”under“+”stand“+”standpoint“=”understand“+”stand“+”point“ The blocks are gathered to a hashtable and prior to storing the blocks to the hashtable, the s_start and s_end are removed from the block. The GUIDs are used as hashtable keys.



4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 4776

def pick_by_instance(s_start,s_end,s_haystack,
   msgcs=Kibuvits_krl171bt4_msgc_stack.new)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_start
      kibuvits_krl171bt4_typecheck bn, String, s_end
      kibuvits_krl171bt4_typecheck bn, String, s_haystack
      kibuvits_krl171bt4_typecheck bn, Kibuvits_krl171bt4_msgc_stack, msgcs
   end # if
   # TODO: refactor the msg out of here and use the Kibuvits_krl171bt4_msgc_stack
   # instead.
   ht_out=Hash.new
   s_hay=s_haystack
   b_failure=false
   msg="ok"
   s_block_substitution=Kibuvits_krl171bt4_GUID_generator.generate_GUID # for inclusion tests
   s_new_ht_key=""
   pick_extraction_step_input_verification(
   s_start, s_end, s_hay, ht_out, s_block_substitution, s_new_ht_key)
   while msg=="ok"
      s_block_substitution=Kibuvits_krl171bt4_GUID_generator.generate_GUID
      s_new_ht_key=s_block_substitution
      msg, s_hay=pick_extraction_step(s_start, s_end,
      s_hay, ht_out,s_block_substitution,s_new_ht_key)
   end # loop
   msgcs.cre msg if msg!="done"
   return s_hay,ht_out
end

#ribboncut(s_needle, s_haystack) ⇒ Object



4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 4942

def ribboncut(s_needle, s_haystack)
   kibuvits_krl171bt4_throw 's_needle==""' if s_needle==""
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_needle
      kibuvits_krl171bt4_typecheck bn, String, s_haystack
   end # if
   ar_out=Array.new
   if !s_haystack.include? s_needle
      ar_out<<""+s_haystack
      return ar_out
   end # if
   if s_haystack==s_needle
      ar_out<<""
      ar_out<<""
      return ar_out
   end # if
   # YYxxxYYmmmmYY    xxxYYYYmmmm
   # 0123456789012    01234567890
   # STR::=(NEEDLE|TOKEN)
   ix_str_low=0
   ix_str_high=nil
   ix_str_start_candidate=0
   ix_hay_max=s_haystack.length-1
   i_needle_len=s_needle.length
   ix_needle_low=nil
   s1=""
   while true
      ix_needle_low=s_haystack.index(s_needle,ix_str_start_candidate)
      if ix_needle_low==nil
         s1=""
         if ix_str_start_candidate<=ix_hay_max
            s1=s_haystack[ix_str_start_candidate..(-1)]
         end # if
         ar_out<<s1
         break
      end # if
      ix_str_start_candidate=ix_needle_low+i_needle_len
      ix_str_high=ix_needle_low-1
      s1=""
      if ix_str_low<=ix_str_high
         s1=s_haystack[ix_str_low..ix_str_high]
         s1="" if s1==s_needle
      end # if
      ar_out<<s1
      ix_str_low=ix_str_start_candidate
   end # loop
   return ar_out
end

#s_batchreplace(ht_needles, s_haystack, b_needle_is_key = true) ⇒ Object

Makes it possible to replace all of the needle strings within the haystack string with a substitution string that contains at least one of the needle strings as one of its substrings.

It’s also useful, when at least one of the needle strings contains at least one other needle string as its substring. For example, if “cat” and “mouse” were to be switched in a sentence like “A cat and a mouse met.”, doing the replacements sequentially, “cat”->“mouse” and “mouse”->“cat”, would give “A cat and a cat met.” in stead of the correct version, “A mouse and a cat met.”

By combining multiple substitutions into a single, “atomic”, operation, one can treat the needle strings of multiple substitutions as a whole, single, set.

A a few additional examples, where it is difficult to do properly with plain substitutions: needle-substitutionstring pairs:

("cat","Casanova")
("nova","catastrophe")

haystack: “A cat saw a nova.” Correct substitution result, as given by the Kibuvits_krl171bt4_str.s_batchreplace:

"A Casanova saw a catastrophe."

Incorrect versions as gained by sequential substitutions:

"A Casacatastrophe saw a catastrophe."
"A Casanova saw a Casanovaastrophe."

if b_needle_is_key==true

ht_needles[<needle string>]==<substitution string>

else

ht_needles[<substitution string>]==<array of needle strings>


5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5075

def s_batchreplace(ht_needles, s_haystack, b_needle_is_key=true)
   # The idea is that "i" in the "Sci-Fi idea" can be replaced
   # with "X" by decomposing the haystack to ar=["Sc","-F"," ","dea"]
   # and treating each of the elements, except the last one, as
   # <a string><substitution string>. The substitution string always stays
   # at the right side, even if the <a string> is decomposed recursively.
   #
   # If the <substitution string> were temporarily replaced with a
   # Globally Unique Identifier (GUID) and concatenated to the <a string>,
   # then there might be difficulties separating the two because in
   # some very rare cases it would be like
   # "aaXXmm"+"XXmmXX"="aaXXmmXXmmXX"="aa"+"XXmmXX"+"mmXX".
   # That's why the <a string> and the <substitution string> are kept
   # as a pair during the processing.
   #
   ar_subst_needle_pairs=nil
   if b_needle_is_key
      ar_subst_needle_pairs=batchreplace_csnps_needle_is_key(
      ht_needles)
   else
      ar_subst_needle_pairs=batchreplace_csnps_subst_is_key(
      ht_needles)
   end # if
   # One wants to replace the longest needles first. So they're
   # placed to the smallest indices of the array.
   # The idea is that for a haystack like "A cat saw a caterpillar",
   # one wants to remove the "caterpillar" from the sentence before
   # the "cat", because by removing the "cat" first one would break
   # the "caterpillar". Strings that have the same length, can't
   # possibly be eachothers' substrings without equaling with eachother.
   ar_subst_needle_pairs.sort!{|a,b| b[1].length<=>a[1].length}
   ar_pieces=Array.new
   ar_piece=[s_haystack, nil]
   ar_pieces<<ar_piece
   ar_subst_needle=$kibuvits_krl171bt4_lc_emptystring
   ar_piece=nil
   ar_pieces2=Array.new
   ar_subst_needle_pairs.length.times do |i|
      ar_subst_needle=ar_subst_needle_pairs[i]
      ar_pieces.length.times do |ii|
         ar_piece=ar_pieces[ii]
         ar_pieces2=ar_pieces2+
         batchreplace_step(ar_piece, ar_subst_needle)
      end # loop
      ar_pieces.clear # May be it facilitates memory reuse.
      ar_pieces=ar_pieces2
      ar_pieces2=Array.new
   end # loop
   n=ar_pieces.length-1
   ar_s=Array.new
   n.times do |i|
      ar_piece=ar_pieces[i]
      ar_s<<ar_piece[0]
      ar_s<<ar_piece[1]
   end # loop
   ar_s<<(ar_pieces[n])[0]
   s_out=kibuvits_krl171bt4_s_concat_array_of_strings(ar_s)
   #s_out.force_encoding("utf-8")
   return s_out
end

#s_escape_for_bash_t1(s_in) ⇒ Object

Kibuvits_krl171bt4_str.s_escape_spaces_t1



5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5789

def s_escape_for_bash_t1(s_in)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_in
   end # if
   s_0=s_in
   s_1=s_0.gsub(/[\\]/,$kibuvits_krl171bt4_lc_4backslashes) # "\" -> "\\"
   # must not be /[\s]/, because the /[\s]/ escapes the "\n".
   s_0=s_1.gsub(/ /,$kibuvits_krl171bt4_lc_escapedspace)
   s_1=s_0.gsub(/[\[]/,"\\[")
   s_0=s_1.gsub(/[{]/,"\\{")
   s_1=s_0.gsub(/[(]/,"\\(")
   s_0=s_1.gsub(/[)]/,"\\)")
   s_1=s_0.gsub(/[\t]/,"\\\t")
   s_0=s_1.gsub(/[\$]/,"\\$")
   s_1=s_0.gsub(/[|]/,"\\|")
   s_0=s_1.gsub(/[>]/,"\\>")
   s_1=s_0.gsub(/[<]/,"\\<")
   s_0=s_1.gsub(/["]/,"\\\"")
   s_1=s_0.gsub(/[']/,"\\\\'")
   s_0=s_1.gsub(/[`]/,"\\\\`")
   s_1=s_0.gsub(/[&]/,"\\\\&")
   s_0=s_1.gsub(/[;]/,"\\\\;")
   s_1=s_0.gsub(/[.]/,"\\.")
   s_out=s_1
   return s_out
end

#s_escape_spaces_t1(s_in) ⇒ Object




5774
5775
5776
5777
5778
5779
5780
5781
5782
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5774

def s_escape_spaces_t1(s_in)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_in
   end # if
   rgx_0=/ / # must not be /[\s]/, because the /[\s]/ escapes the "\n".
   s_out=s_in.gsub(rgx_0,$kibuvits_krl171bt4_lc_escapedspace)
   return s_out
end

#s_get_substring_by_bounds(s_haystack, s_start, s_end, msgcs = Kibuvits_krl171bt4_msgc_stack.new) ⇒ Object

Returns substring of the s_haystack. The output does not contain the s_start and s_end, i.e. the s_start and s_end have been “trimmed” away. The output may be an empty string. It’s OK for the bounds to reside at separate lines, but they both have to exist.



6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6513

def s_get_substring_by_bounds(s_haystack,s_start,s_end,
   msgcs=Kibuvits_krl171bt4_msgc_stack.new)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_haystack
      kibuvits_krl171bt4_typecheck bn, String, s_start
      kibuvits_krl171bt4_typecheck bn, String, s_end
      kibuvits_krl171bt4_typecheck bn, Kibuvits_krl171bt4_msgc_stack, msgcs
      kibuvits_krl171bt4_assert_string_min_length(bn,s_start,1)
      kibuvits_krl171bt4_assert_string_min_length(bn,s_end,1)
      msgcs.assert_lack_of_failures(
      "GUID='c7675041-5282-4d04-82df-c13290a118e7'")
   end # if
   s_out=""
   i_start=s_haystack.index(s_start)
   if i_start==nil
      s_message_id="s_get_substring_by_bounds_err_0"
      s_msg_en="The start bound, s_start==\""+s_start+
      "\", is missing from the haystack."
      s_msg_ee="Algust markeeriv sõne, s_start==\""+
      s_start+"\", on uuritavast tekstist puudu."
      msgcs.cre(s_msg_en,s_message_id,true)
      msgcs.last[$kibuvits_krl171bt4_lc_Estonian]=s_msg_ee
      return s_out;
   end # if
   i_end=s_haystack.index(s_end)
   if i_end==nil
      s_message_id="s_get_substring_by_bounds_err_1"
      s_msg_en="The end bound, s_end==\""+s_end+
      "\", is missing from the haystack."
      s_msg_ee="Lõppu markeeriv sõne, s_end==\""+
      s_end+"\", on uuritavast tekstist puudu."
      msgcs.cre(s_msg_en,s_message_id,true)
      msgcs.last[$kibuvits_krl171bt4_lc_Estonian]=s_msg_ee
      return s_out;
   end # if
   if i_end<=i_start
      s_message_id="s_get_substring_by_bounds_err_3"
      s_msg_en="The end bound ,i_end=="+i_end.to_s+
      ", s_end==\""+s_end+
      "\", resided at a lower index than the start bound, s_start=\""+
      s_start+"\", i_start=="+i_start.to_s+"."
      s_msg_ee="Lõppu markeeriv sõne, s_end==\""+s_end+
      "\", asus madalamal indeksil, i_end=="+i_end.to_s+
      ", kui algust markeeriv sõne, i_start=="+s_start.to_s+"."
      msgcs.cre(s_msg_en,s_message_id,true)
      msgcs.last[$kibuvits_krl171bt4_lc_Estonian]=s_msg_ee
      return s_out;
   end # if
   s_out=s_haystack[(i_start+s_start.length)..(i_end-1)]
   return s_out
end

#s_i2unicode(i_codepoint) ⇒ Object

It converts a Unicode codepoint to a single character string.

It’s partly derived from a Unicode utility written by David Flangan: www.davidflanagan.com/2007/08/index.html#000136



6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6488

def s_i2unicode(i_codepoint)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, Fixnum, i_codepoint
   end # if
   if (i_codepoint<0)||(@i_unicode_maximum_codepoint<i_codepoint)
      raise("i_codepoint=="+i_codepoint.to_s+
      ", but the valid range is 0 to "+@i_unicode_maximum_codepoint.to_s)
   end # end
   s_out=[i_codepoint].pack("U")
   return s_out
end

#s_paintrollerreplace(s_or_rgx_needle_id_est_stripe_placeholder, s_or_ar_of_substitution_strings_or_a_function_ie_stripes, s_haystack) ⇒ Object

The core idea is that if stripes of multiple colors are painted side by side and a paint roller is rolled across the stripes, so that the path of the paint roller intersects the stripes, then the paint roller can be used for painting a repeating pattern of the stripes at some other place.

If the s_or_rgx_needle is a string, then it is used as a searchstring, not as a regular expression constructor parameter.

The substitution string can be supplied by a function that takes an iteration index, starting from 0, as a parameter. An example, how to crate a 3-stripe provider:



5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5159

def s_paintrollerreplace(s_or_rgx_needle_id_est_stripe_placeholder,
   s_or_ar_of_substitution_strings_or_a_function_ie_stripes, s_haystack)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, [Regexp,String], s_or_rgx_needle_id_est_stripe_placeholder
      kibuvits_krl171bt4_typecheck bn, [Proc,Array,String], s_or_ar_of_substitution_strings_or_a_function_ie_stripes
      kibuvits_krl171bt4_typecheck bn, String, s_haystack
   end # if
   #-------
   rgx_needle=s_or_rgx_needle_id_est_stripe_placeholder
   cl=rgx_needle.class
   if cl==String
      rgx_needle=Regexp.new(s_or_rgx_needle_id_est_stripe_placeholder)
      cl=Regexp
   end # if
   if cl!=Regexp
      kibuvits_krl171bt4_throw("rgx_needle.class=="+cl.to_s+
      "\n GUID='a6518325-e5a7-49c6-a151-c13290a118e7'\n\n")
   end # if
   #-------
   func_paintroller=s_or_ar_of_substitution_strings_or_a_function_ie_stripes
   cl=func_paintroller.class
   if cl==String
      func_paintroller=[func_paintroller]
      cl=Array
   end # if
   ar_stripes=nil
   if cl==Array
      ar_stripes=func_paintroller
      func_paintroller=lambda do |i_n|
         i_sz=ar_stripes.size
         if KIBUVITS_krl171bt4_b_DEBUG
            if i_n<0
               kibuvits_krl171bt4_throw("i_n == "+i_n.to_s+" < 0 "+
               "\n GUID='5dc63038-120a-4629-9241-c13290a118e7'\n\n")
            end # if
            if i_sz<1
               kibuvits_krl171bt4_throw("ar_stripes.size == "+i_sz.to_s+" < 1 "+
               "\n GUID='253263d4-9d6f-40dd-9921-c13290a118e7'\n\n")
            end # if
         end # if
         i_ix=i_n%i_sz
         x_out=ar_stripes[i_ix]
         if KIBUVITS_krl171bt4_b_DEBUG
            if x_out.class!=String # to avoid the string instantiation
               bn=binding()
               msg="i_n=="+i_n.to_s+" i_sz=="+i_sz.to_s+" i_ix=="+i_ix.to_s+
               "\n GUID='1ceb3c46-f652-491d-8411-c13290a118e7'\n\n"
               kibuvits_krl171bt4_typecheck bn, String, x_out, msg
            end # if
         end # if
         return x_out
      end # func
      cl=Proc
   end # if
   if KIBUVITS_krl171bt4_b_DEBUG
      if cl!=Proc
         kibuvits_krl171bt4_throw("func_paintroller.class=="+cl.to_s+
         "\n GUID='fb181e47-8928-44cc-8301-c13290a118e7'\n\n")
      end # if
      if !func_paintroller.lambda?
         # There are 2 different types of Proc instances:
         # plain Ruby blocks and the ones that are created with the
         # lambda keyword.
         kibuvits_krl171bt4_throw("func_paintroller.lambda? != true"+
         "\n GUID='5aedd68a-423e-4e5e-94e0-c13290a118e7'\n\n")
      end # if
   end # if
   #-------
   s_hay=s_haystack
   ar_s=Array.new
   md=nil
   ar_pair_and_speedhack=Array.new(2,$kibuvits_krl171bt4_lc_emptystring)
   s_left=nil
   s_right=nil
   ix_paintroller=0
   while true
      md=s_hay.match(rgx_needle)
      break if md==nil
      # At this line the separator always exists in the s_hay.
      ar_pair_and_speedhack=ar_bisect(s_hay,md[0],ar_pair_and_speedhack)
      s_left=ar_pair_and_speedhack[0]
      s_right=ar_pair_and_speedhack[1]
      if s_left==$kibuvits_krl171bt4_lc_emptystring
         ar_s<<func_paintroller.call(ix_paintroller)
         s_hay=s_right
      else
         ar_s<<s_left
         ar_s<<func_paintroller.call(ix_paintroller)
         s_hay=s_right
         break if s_right==$kibuvits_krl171bt4_lc_emptystring
      end # if
      ix_paintroller=ix_paintroller+1
   end # loop
   ar_s<<s_hay
   s_out=kibuvits_krl171bt4_s_concat_array_of_strings(ar_s)
   return s_out
end

#s_s_bisect_by_header_t1(s_in, msgcs) ⇒ Object

Header is in a form:

header_data_length_in_decimaldigits|header_data|therest_of_the_string

Throws, if the header is not found. Returns a pair, (s_left, s_right), where

s_left == header_data

s_right == therest_of_the_string

The header_data and the therest_of_the_string can be empty strings.

An example:

s_in=="11|abc abc abc|the rest of the text"

s_left,s_right=s_s_bisect_by_header_t1(s_in)

 s_left=="abc abc abc"
s_right=="the rest of the text"

The header based architecture is useful, when working with files that do not fit into available RAM.



5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5489

def s_s_bisect_by_header_t1(s_in,msgcs)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_in
      kibuvits_krl171bt4_typecheck bn, Kibuvits_krl171bt4_msgc_stack, msgcs
      msgcs.assert_lack_of_failures(
      "GUID='106e821c-dac2-49d6-8280-c13290a118e7'")
   end # if
   s_left=$kibuvits_krl171bt4_lc_emptystring
   s_right=$kibuvits_krl171bt4_lc_emptystring
   rgx=/^[\d]+[|]/
   md=s_in.match(rgx)
   if md==nil
      s_default_msg="Header data length is missing."
      s_message_id="data_fault_t1"
      b_failure=true
      msgcs.cre(s_default_msg,s_message_id,b_failure,
      "d61ccc3e-4ea4-46ec-8234-c13290a118e7")
      return s_left,s_right
   end # if
   i_len_s_in=s_in.length # s_in=="10|heder_data|therestofblabla"
   s_0=md[0] # "10|"
   i_len_header_data=(s_0[0..(-2)]).to_i # "10".to_i
   i_len_s_0=s_0.length
   if (i_len_s_in-i_len_s_0-i_len_header_data-1)<0
      # It's OK for the therestofblabla to be an empty string.
      s_default_msg="\nFlawed header. i_len_header_data =="+
      i_len_header_data.to_s+
      "\ncontradicts with s_in.length == "+i_len_s_in.to_s
      s_message_id="data_fault_t2"
      b_failure=true
      msgcs.cre(s_default_msg,s_message_id,b_failure,
      "e435d24b-a310-4103-bb14-c13290a118e7")
      return s_left,s_right
   end # if
   # Due to the regular expression, rgx, 2<=i_len_s_0
   s_1=s_in[i_len_s_0..(-1)] # "heder_data|therestofblabla"
   # It's OK for the header_data to be an empty string.
   ixs_low=0
   ixs_high=i_len_header_data
   s_left=Kibuvits_krl171bt4_ix.sar(s_1,ixs_low,ixs_high)
   # However, the header might not exist, if the
   # s_1=="heder_data_therestofblabla"
   if s_1[i_len_header_data..i_len_header_data]!=$kibuvits_krl171bt4_lc_pillar
      s_default_msg="\nFlawed header, i.e. the header is considered\n"+
      "to be missing, because the header data block is \n"+
      "not followed by a \"pillar character\" (\"|\"). \n"+
      "\n GUID='8845b12d-be66-4584-b470-c13290a118e7'\n\n"
      s_message_id="data_fault_t3"
      b_failure=true
      msgcs.cre(s_default_msg,s_message_id,b_failure,
      "8c340551-9ce1-4df2-b3e3-c13290a118e7")
      return s_left,s_right
   end # if
   # In Ruby "x"[1..(-1)]==""
   #         "x"[2..(-1)]==nil
   s_right=s_1[(i_len_header_data+1)..(-1)] # +1 due to the "|"
   return s_left,s_right
end

#s_to_s_with_assured_amount_of_digits_t1(i_minimum_amount_of_digits, i_positive_whole_number) ⇒ Object

Precedes the i_in.to_s with zeros (“0”) so that the i_minimum_amount_of_digits<=s_out.length .



6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6578

def s_to_s_with_assured_amount_of_digits_t1(i_minimum_amount_of_digits,
   i_positive_whole_number)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, Fixnum, i_minimum_amount_of_digits
      kibuvits_krl171bt4_typecheck bn, [Fixnum,Bignum], i_positive_whole_number
      kibuvits_krl171bt4_assert_is_smaller_than_or_equal_to(bn,
      1, i_minimum_amount_of_digits,
      "GUID='ec379843-cf0f-41d2-b1cf-c13290a118e7'")
      kibuvits_krl171bt4_assert_is_smaller_than_or_equal_to(bn,
      0, i_positive_whole_number,
      "GUID='a3390b65-b051-485e-b3bf-c13290a118e7'")
   end # if
   s_0=i_positive_whole_number.to_s
   i_0=i_minimum_amount_of_digits-s_0.length
   s_0=("0"*i_0)+s_0 if 0<i_0
   return s_0
end

#snatch_n_times_t1(s_haystack, s_separator, n) ⇒ Object

Returns an array of strings that contains only the snatched string pieces.



5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5392

def snatch_n_times_t1(s_haystack,s_separator,n)
   # If one updates this code, then one should also copy-paste
   # an updated version of this method to the the ProgFTE implementation.
   # The idea behind such an arrangement is that the ProgFTE implementation
   # is not allowed to have any dependencies other than the library booting code.
   if @b_kibuvits_krl171bt4_bootfile_run
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_haystack
      kibuvits_krl171bt4_typecheck bn, String, s_separator
      kibuvits_krl171bt4_typecheck bn, Fixnum, n
   end # if
   if(s_separator=="")
      exc=Exception.new("\nThe separator string had a "+
      "value of \"\", but empty strings are not "+
      "allowed to be used as separator strings.\n"+
      "GUID='4930ae12-971a-4307-b4d0-c13290a118e7'\n\n")
      if @b_kibuvits_krl171bt4_bootfile_run
         kibuvits_krl171bt4_throw(exc)
      else
         raise(exc)
      end # if
   end # if
   s_hay=s_haystack
   if s_hay.length==0
      exc=Exception.new("s_haystack.length==0 \n"+
      "GUID='41901718-23f2-4e91-b5c0-c13290a118e7'\n\n")
      if @b_kibuvits_krl171bt4_bootfile_run
         kibuvits_krl171bt4_throw(exc)
      else
         raise(exc)
      end # if
   end # if
   # It's a bit vague, whether '' is also present at the
   # very end and very start of the string or only between
   # characters. That's why there's a limitation, that the
   # s_separator may not equal with the ''.
   if s_separator.length==0
      exc=Exception.new("s_separator.length==0\n"+
      "GUID='a1941958-1f8a-4fb9-b1b0-c13290a118e7'\n\n")
      if @b_kibuvits_krl171bt4_bootfile_run
         kibuvits_krl171bt4_throw(exc)
      else
         raise(exc)
      end # if
   end # if
   s_hay=""+s_haystack
   ar=Array.new
   ar1=Array.new(2,"")
   n.times do |i|
      ar1=ar_bisect(s_hay,s_separator,ar1)
      ar<<ar1[0]
      s_hay=ar1[1]
      if (s_hay=='') and ((i+1)<n)
         exc=Exception.new("Expected number of separators is "+n.to_s+
         ", but the s_haystack contained only "+(i+1).to_s+
         "separator strings.\n"+
         "GUID='5cbdb182-bc9d-4846-a590-c13290a118e7'\n\n")
         if @b_kibuvits_krl171bt4_bootfile_run
            kibuvits_krl171bt4_throw(exc)
         else
            raise(exc)
         end # if
      end # if
   end # loop
   return ar;
end

#str2strliteral(s_in, s_quotation_mark = $kibuvits_krl171bt4_lc_doublequote, b_escape_quotation_marks = true, b_escape_backslashes = true, s_concatenation_mark = "+") ⇒ Object



6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6396

def str2strliteral(s_in,s_quotation_mark=$kibuvits_krl171bt4_lc_doublequote,
   b_escape_quotation_marks=true, b_escape_backslashes=true,
   s_concatenation_mark="+")
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_in
      kibuvits_krl171bt4_typecheck bn, String, s_quotation_mark
      kibuvits_krl171bt4_typecheck bn, [FalseClass,TrueClass], b_escape_quotation_marks
      kibuvits_krl171bt4_typecheck bn, [FalseClass,TrueClass], b_escape_backslashes
      kibuvits_krl171bt4_typecheck bn, String, s_concatenation_mark
   end # if
   s=s_in
   s=s.gsub("\\","\\\\\\\\") if b_escape_backslashes
   s=s.gsub(s_quotation_mark,"\\"+s_quotation_mark) if b_escape_quotation_marks
   s_out=""
   b_nonfirst=false
   s_tmp=nil
   s_separator=s_concatenation_mark+$kibuvits_krl171bt4_lc_linebreak
   s.each_line do |s_line|
      s_out=s_out+s_separator if b_nonfirst
      s_tmp=Kibuvits_krl171bt4_str.clip_tail_by_str(s_line,$kibuvits_krl171bt4_lc_linebreak)
      s_tmp=s_quotation_mark+s_tmp+s_quotation_mark
      s_out=s_out+s_tmp
      b_nonfirst=true
   end # loop
   return s_out
end

#str_contains_spacestabslinebreaks(s_candidate) ⇒ Object

Returns true, if the s_candidate contains at least one linebreak, space or tabulation character.



6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6437

def str_contains_spacestabslinebreaks(s_candidate)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_candidate
   end # if
   s=normalise_linebreaks(s_candidate)
   i_len1=s.length
   s=s.gsub(/[\s\t\n]/,"")
   i_len2=s.length
   b_out=(i_len1!=i_len2)
   return b_out;
end

#surround_lines(s_line_prefix, s_text, s_line_suffix, b_s_text_has_been_normalized_to_use_unix_line_breaks = false) ⇒ Object

The b_s_text_has_been_normalized_to_use_unix_line_breaks exists only because the line-break normalization can be expensive, specially if it is called very often, for example, during the processing of a “big” set of “small” strings.



6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6202

def surround_lines(s_line_prefix,s_text,s_line_suffix,
   b_s_text_has_been_normalized_to_use_unix_line_breaks=false)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_line_prefix
      kibuvits_krl171bt4_typecheck bn, String, s_text
      kibuvits_krl171bt4_typecheck bn, String, s_line_suffix
      kibuvits_krl171bt4_typecheck bn, [TrueClass,FalseClass], b_s_text_has_been_normalized_to_use_unix_line_breaks
   end # if
   s_in=s_text
   if !b_s_text_has_been_normalized_to_use_unix_line_breaks
      s_in=Kibuvits_krl171bt4_str.normalise_linebreaks(s_text, $kibuvits_krl171bt4_lc_linebreak)
   end # if
   s_out=""
   s_cropped=nil
   b_nonfirst=false
   s_in.each_line do |s_line|
      s_out=s_out+$kibuvits_krl171bt4_lc_linebreak if b_nonfirst
      b_nonfirst=true
      s_cropped=clip_tail_by_str(s_line, $kibuvits_krl171bt4_lc_linebreak)
      s_out=s_out+s_line_prefix+s_cropped+s_line_suffix
   end # loop
   return s_out
end

#trim(s_string) ⇒ Object

Removes spaces, line breaks and tabs from the start and end of the string.



5960
5961
5962
5963
5964
5965
5966
5967
5968
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 5960

def trim(s_string)
   if KIBUVITS_krl171bt4_b_DEBUG
      kibuvits_krl171bt4_typecheck binding(), String, s_string
   end # if
   rgx=/^[\s\t\r\n]+/
   s_out=s_string.gsub(rgx,$kibuvits_krl171bt4_lc_emptystring)
   s_out=s_out.reverse.gsub(rgx,$kibuvits_krl171bt4_lc_emptystring).reverse
   return s_out
end

#verify_noninclusion(array_of_strings) ⇒ Object

For ab, bb, ba it checks that there does not exist any pairs, where one element is equal to or substring of the other. It also checks that no element is a substring of the pair concatenation. For example, a pair (ab,ba) has concatenations abba, baab, and the abba contains the element bb as its substring.



4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 4629

def verify_noninclusion(array_of_strings)
   b_inclusion_present=false
   msg="Inclusions not found."
   ar_str=array_of_strings
   ht=Hash.new
   ar_str.each do |s_1|
      if ht.has_key?(s_1)
         b_inclusion_present=true
         msg="String \""+s_1+"\" is within the array more than once."
         return b_inclusion_present,msg
      end # if
   end # if
   # All of the pixels of a width*height sized image can
   # be encoded to a single array that has width*height elements.
   # The array index determines the X and Y of the pixel.
   # The pixel coordinates are pairs. The width of a square
   # equals its height. :-)
   i_side=ar_str.length
   s_1=""
   s_2=""
   s_concat=""
   s_elem=""
   i_side.times do |y|
      s_2=ar_str[y]
      i_side.times do |x|
         next if x==y
         s_1=ar_str[x]
         if (s_1.index(s_2)!=nil)
            b_inclusion_present=true
            msg="\""+s_1+"\" includes \""+s_2+"\""
            break
         end # if
         if (s_2.index(s_1)!=nil)
            b_inclusion_present=true
            msg="\""+s_2+"\" includes \""+s_1+"\""
            break
         end # if
         # abba+bball=abbABBAll, which contains abba twice, but
         # it is not a problem, because if the first abba is
         # removed, the second one also breaks.
         s_concat=s_1+s_2
         i_side.times do |i_elem|
            next if (i_elem==x)||(i_elem==y)
            s_elem=ar_str[i_elem]
            if (s_concat.index(s_elem)!=nil)
               b_inclusion_present=true
               msg="Concatenation \""+s_concat+"\" includes \""+
               s_elem+"\""
               break
            end # if
         end # loop
         break if b_inclusion_present
         s_concat=s_2+s_1
         i_side.times do |i_elem|
            next if (i_elem==x)||(i_elem==y)
            s_elem=ar_str[i_elem]
            if (s_concat.index(s_elem)!=nil)
               b_inclusion_present=true
               msg="Concatenation \""+s_concat+"\" includes \""+
               s_elem+"\""
               break
            end # if
         end # loop
         break if b_inclusion_present
      end # loop
      break if b_inclusion_present
   end # loop
   return b_inclusion_present,msg
end

#verify_s_is_within_domain(s_to_test, s_or_ar_of_domain_elements, msgcs, s_action_on_verification_failure = "note_in_msgcs", s_language_to_use_for_printing = $kibuvits_krl171bt4_lc_English) ⇒ Object

The s_actio_on_verification_failure has the following domain: “note_in_msgcs”,“throw”,“print_and_exit”,“exit”



6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 6328

def verify_s_is_within_domain(s_to_test,s_or_ar_of_domain_elements,
   msgcs,s_action_on_verification_failure="note_in_msgcs",
   s_language_to_use_for_printing=$kibuvits_krl171bt4_lc_English)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_to_test
      kibuvits_krl171bt4_typecheck bn, [Array,String], s_or_ar_of_domain_elements
      kibuvits_krl171bt4_typecheck bn, Kibuvits_krl171bt4_msgc_stack, msgcs
      kibuvits_krl171bt4_typecheck bn, String, s_action_on_verification_failure
      kibuvits_krl171bt4_typecheck bn, String, s_language_to_use_for_printing
   end # if
   s_cache_key='verify_s_is_within_domain_actions'
   ht_action_domain=nil
   if !@@cache.has_key? s_cache_key
      ht_action_domain=Hash.new
      i=42
      ht_action_domain["note_in_msgcs"]=i
      ht_action_domain["throw"]=i
      ht_action_domain["print_and_exit"]=i
      ht_action_domain["exit"]=i
      @@cache[s_cache_key]=ht_action_domain
   else
      ht_action_domain=@@cache[s_cache_key]
   end # if
   if !ht_action_domain.has_key? s_action_on_verification_failure
      s="s_action_on_verification_failure==\""+
      s_action_on_verification_failure+"\", but supported values are: "
      ar=Array.new
      ht_action_domain.each_key{|x| ar<<x}
      s=s+array2xseparated_list(ar)
      kibuvits_krl171bt4_throw s
   end # if
   ar_domain=Kibuvits_krl171bt4_ix.normalize2array(s_or_ar_of_domain_elements)
   b_verification_failed=verify_s_is_within_domain_check(s_to_test,ar_domain)
   return if !b_verification_failed
   s_domain=array2xseparated_list(ar_domain)
   s_msg_en="s_to_test==\""+s_to_test+"\", but it is expected to be \n"+
   "one of the following: "+s_domain+" ."
   s_msg_ee="s_to_test==\""+s_to_test+"\", kuid ta peaks omama \n"+
   "ühte järgnevaist väärtustest: "+s_domain+" ."
   msgcs.cre(s_msg_en,1.to_s)
   msgcs.last[$kibuvits_krl171bt4_lc_Estonian]=s_msg_ee
   case s_action_on_verification_failure
   when "throw"
      kibuvits_krl171bt4_throw msgcs.to_s(s_language_to_use_for_printing)
   when "note_in_msgcs"
      # One does nothing.
   when "print_and_exit"
      kibuvits_krl171bt4_writeln msgcs.to_s(s_language_to_use_for_printing)
      exit
   when "exit"
      exit
   else
      kibuvits_krl171bt4_throw "s_action_on_verification_failure=="+s_action_on_verification_failure.to_s
   end # case
end

#wholenumber_ASCII_2_whonenumber_Unicode(i_ascii) ⇒ Object

According to www.alanwood.net/demos/ansi.html there exist codepoints, where the integer representation of an ASCII character does not match with the character’s integer representation in the Unicode.



4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 4883

def wholenumber_ASCII_2_whonenumber_Unicode(i_ascii)
   if KIBUVITS_krl171bt4_b_DEBUG
      kibuvits_krl171bt4_typecheck binding(), Fixnum, i_ascii
   end # if
   b_failure=false
   msg="ASCII 2 Unicode conversion succeeded."
   i_out=0
   if (i_ascii<32)||(0xFF<i_ascii)
      if (i_ascii==0xA)||(i_ascii==0xD) # "\n" and "\r"
         i_out=i_ascii
         return b_failure, i_out, msg
      end # end
      msg="ASCII 2 Unicode conversion failed. i_ascii=="+i_ascii.to_s(16)
      b_failure=true
      return b_failure, i_out, msg
   end # end
   if (i_ascii<=0x7f)||(0xA0<=i_ascii)
      i_out=i_ascii
      return b_failure, i_out, msg
   end # if
   Kibuvits_krl171bt4_str.wholenumber_ASCII_2_whonenumber_Unicode_init1
   whncses=@@cache['whncses']
   if whncses.has_key? i_ascii
      i_out=0+whncses[i_ascii]
      return b_failure, i_out, msg
   end # if
   b_failure=true
   msg="ASCII 2 Unicode conversion failed. i_ascii=="+i_ascii.to_s(16)
   return b_failure, i_out, msg
end