Module: Antlr4Native::StringHelpers

Extended by:
StringHelpers
Included in:
Context, Generator, StringHelpers, VisitorGenerator
Defined in:
lib/antlr4-native/string_helpers.rb

Instance Method Summary collapse

Instance Method Details

#capitalize(str) ⇒ Object


3
4
5
# File 'lib/antlr4-native/string_helpers.rb', line 3

def capitalize(str)
  str.sub(/\A(.)/) { $1.upcase }
end

#dasherize(str) ⇒ Object


15
16
17
# File 'lib/antlr4-native/string_helpers.rb', line 15

def dasherize(str)
  underscore(str).gsub('_', '-')
end

#underscore(str) ⇒ Object


7
8
9
10
11
12
13
# File 'lib/antlr4-native/string_helpers.rb', line 7

def underscore(str)
  str
    .gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .gsub('-', '_')
    .downcase
end