Module: XSD::CodeGen::GenSupport

Included in:
SOAP::Generator, WSDL::SOAP::ClassDefCreatorSupport, WSDL::SOAP::ClassNameCreator, WSDL::SOAP::ServantSkeltonCreator, ClassDef, CommentDef, MethodDef, ModuleDef
Defined in:
lib/xsd/codegen/gensupport.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) capitalize(target)



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

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

+ (Boolean) constant?(word)

Returns:

  • (Boolean)


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

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

+ (Boolean) keyword?(word)

Returns:

  • (Boolean)


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

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

+ (Object) safeconstname(name)



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

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

+ (Boolean) safeconstname?(name)

Returns:

  • (Boolean)


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

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

+ (Object) safemethodname(name)



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

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

+ (Boolean) safemethodname?(name)

Returns:

  • (Boolean)


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

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

+ (Object) safevarname(name)



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

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

+ (Boolean) safevarname?(name)

Returns:

  • (Boolean)


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

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

+ (Object) uncapitalize(target)



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

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

Instance Method Details

- (Object) format(str, indent = nil)



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

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