Module: TextClean

Defined in:
lib/text_clean.rb,
lib/text_clean/version.rb,
ext/text_clean/text_clean.cc

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.clean(text, line_sep = "\n") ⇒ Object



5
6
7
8
# File 'lib/text_clean.rb', line 5

def self.clean(text, line_sep = "\n")
  # Call the C function
  text_clean(text, line_sep)
end

.text_clean(text, ending) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'ext/text_clean/text_clean.cc', line 94

static VALUE text_clean(VALUE self, VALUE text, VALUE ending) {
  char*   ptext = RSTRING_PTR(text);
  long      len = RSTRING_LEN(text);
  char line_sep = '.';

  if (RSTRING_LEN(ending) == 1) {
    line_sep = RSTRING_PTR(ending)[0];
  }

  rb_str_modify(text);

  size_t new_length = text_clean_cstr(ptext, len, line_sep);

  rb_str_set_len(text, (long)new_length);

  return text;
}