Module: Ritsu::Utility::Strings

Included in:
Project, Target
Defined in:
lib/ritsu/utility/strings.rb

Class Method Summary collapse

Class Method Details

.convert_whitespaces_to_spaces(str, options = {}) ⇒ Object



28
29
30
31
# File 'lib/ritsu/utility/strings.rb', line 28

def convert_whitespaces_to_spaces(str, options={})
  options = {:soft_tab => 4}.merge(options)
  str.sub("\t", " "*options[:soft_tab]).sub(/\n\r/, "")
end

.first(len, str) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/ritsu/utility/strings.rb', line 14

def first(len, str)
  if str.length > count
    str[0..(len-1)]
  else
    str
  end
end

.is_c_name?(str) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/ritsu/utility/strings.rb', line 9

def is_c_name?(str)
  str =~ /^[A-Za-z_]\w*$/
end

.is_underscore_case?(str) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/ritsu/utility/strings.rb', line 4

def is_underscore_case?(str)
  str =~ /^[a-z_][0-9a-z_]*$/
end

.leading_spaces(str, options = {}) ⇒ Object



34
35
36
37
# File 'lib/ritsu/utility/strings.rb', line 34

def leading_spaces(str, options={})
  Ritsu::Utility::Strings.convert_whitespaces_to_spaces(
    Ritsu::Utility::Strings.leading_whitespaces(str), options)
end

.leading_whitespaces(str) ⇒ Object



23
24
25
# File 'lib/ritsu/utility/strings.rb', line 23

def leading_whitespaces(str)
  /^\s*/.match(str)[0]
end