/tutorial/regular_expression/example2.e

http://github.com/tybor/Liberty · Specman e · 39 lines · 24 code · 3 blank · 12 comment · 0 complexity · 50d69bbd42d2f0296bcc952879b39db5 MD5 · raw file

  1. class EXAMPLE2
  2. --
  3. -- How to do substitution with Liberty Eiffel:
  4. --
  5. -- compile -o example2 -boost example2
  6. --
  7. create {ANY}
  8. make
  9. feature {ANY}
  10. make
  11. local
  12. factory: REGULAR_EXPRESSION_BUILDER; se: REGULAR_EXPRESSION
  13. do
  14. -- Use "LibertyEiffel" as spelling.
  15. -- Create the regular expression from the pattern.
  16. se := factory.convert_posix_pattern("[lL]iberty.?[eE]iffel")
  17. check
  18. -- The given pattern is valid. Else, consult
  19. -- factory.last_error_message and factory.last_error_position
  20. se /= Void
  21. end
  22. -- Defines the substitution
  23. se.prepare_substitution("LibertyEiffel")
  24. check
  25. -- This substitution pattern is valid!
  26. se.substitution_pattern_ready
  27. end
  28. io.put_string("Please write some text.%N")
  29. io.read_line
  30. -- Translate to the proper speeling.
  31. se.substitute_all_in(io.last_string)
  32. io.put_string("The proper spelling is: ")
  33. io.put_string(io.last_string)
  34. io.put_new_line
  35. end
  36. end -- class EXAMPLE2