Module: XSD::CodeGen::GenSupport

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.capitalize(target) ⇒ Object


157
158
159
# File 'lib/xsd/codegen/gensupport.rb', line 157

def capitalize(target)
  target.sub(/^([a-z])/) { $1.upcase }
end

.constant?(word) ⇒ Boolean


222
223
224
# File 'lib/xsd/codegen/gensupport.rb', line 222

def constant?(word)
  CONSTANTS.key?(word)
end

.keyword?(word) ⇒ Boolean


217
218
219
# File 'lib/xsd/codegen/gensupport.rb', line 217

def keyword?(word)
  KEYWORDS.key?(word)
end

.safeconstname(name) ⇒ Object


167
168
169
170
171
172
173
174
175
176
# File 'lib/xsd/codegen/gensupport.rb', line 167

def safeconstname(name)
  safename = name.scan(/[a-zA-Z0-9_]+/).collect { |ele|
    GenSupport.capitalize(ele)
  }.join
  if /\A[A-Z]/ !~ safename or keyword?(safename) or constant?(safename)
    "C_#{safename}"
  else
    safename
  end
end

.safeconstname?(name) ⇒ Boolean


179
180
181
# File 'lib/xsd/codegen/gensupport.rb', line 179

def safeconstname?(name)
  /\A[A-Z][a-zA-Z0-9_]*\z/ =~ name and !keyword?(name)
end

.safemethodname(name) ⇒ Object


184
185
186
187
188
189
190
191
192
193
194
# File 'lib/xsd/codegen/gensupport.rb', line 184

def safemethodname(name)
  postfix = name[/[=?!]$/]
  safename = name.scan(/[a-zA-Z0-9_]+/).join('_')
  safename = uncapitalize(safename)
  safename += postfix if postfix
  if /\A[a-z]/ !~ safename or keyword?(safename)
    "m_#{safename}"
  else
    safename
  end
end

.safemethodname?(name) ⇒ Boolean


197
198
199
# File 'lib/xsd/codegen/gensupport.rb', line 197

def safemethodname?(name)
  /\A[a-zA-Z_][a-zA-Z0-9_]*[=!?]?\z/ =~ name and !keyword?(name)
end

.safevarname(name) ⇒ Object


202
203
204
205
206
207
208
209
# File 'lib/xsd/codegen/gensupport.rb', line 202

def safevarname(name)
  safename = uncapitalize(name.scan(/[a-zA-Z0-9_]+/).join('_'))
  if /\A[a-z]/ !~ safename or keyword?(safename)
    "v_#{safename}"
  else
    safename
  end
end

.safevarname?(name) ⇒ Boolean


212
213
214
# File 'lib/xsd/codegen/gensupport.rb', line 212

def safevarname?(name)
  /\A[a-z_][a-zA-Z0-9_]*\z/ =~ name and !keyword?(name)
end

.uncapitalize(target) ⇒ Object


162
163
164
# File 'lib/xsd/codegen/gensupport.rb', line 162

def uncapitalize(target)
  target.sub(/^([A-Z])/) { $1.downcase }
end

Instance Method Details

#format(str, indent = nil) ⇒ Object


227
228
229
230
231
232
233
234
235
# File 'lib/xsd/codegen/gensupport.rb', line 227

def format(str, indent = nil)
  str = trim_eol(str)
  str = trim_indent(str)
  if indent
    str.to_s.gsub(/^/, " " * indent)
  else
    str
  end
end