cmStringCommand.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmStringCommand_h
  14. #define cmStringCommand_h
  15. #include "cmStandardIncludes.h"
  16. #include "cmCommand.h"
  17. /** \class cmStringCommand
  18. * \brief Common string operations
  19. *
  20. */
  21. class cmStringCommand : public cmCommand
  22. {
  23. public:
  24. /**
  25. * This is a virtual constructor for the command.
  26. */
  27. virtual cmCommand* Clone()
  28. {
  29. return new cmStringCommand;
  30. }
  31. /**
  32. * This is called when the command is first encountered in
  33. * the CMakeLists.txt file.
  34. */
  35. virtual bool InitialPass(std::vector<std::string> const& args);
  36. /**
  37. * The name of the command as specified in CMakeList.txt.
  38. */
  39. virtual const char* GetName() { return "STRING";}
  40. /**
  41. * Succinct documentation.
  42. */
  43. virtual const char* GetTerseDocumentation()
  44. {
  45. return "String operations.";
  46. }
  47. /**
  48. * More documentation.
  49. */
  50. virtual const char* GetFullDocumentation()
  51. {
  52. return
  53. " STRING(REGEX MATCH <regular_expression>\n"
  54. " <output variable> <input> [<input>...])\n"
  55. " STRING(REGEX MATCHALL <regular_expression>\n"
  56. " <output variable> <input> [<input>...])\n"
  57. " STRING(REGEX REPLACE <regular_expression>\n"
  58. " <replace_expression> <output variable>\n"
  59. " <input> [<input>...])\n"
  60. " STRING(COMPARE EQUAL <string1> <string2> <output variable>)\n"
  61. " STRING(COMPARE NOTEQUAL <string1> <string2> <output variable>)\n"
  62. " STRING(COMPARE LESS <string1> <string2> <output variable>)\n"
  63. " STRING(COMPARE GREATER <string1> <string2> <output variable>)\n"
  64. " STRING(ASCII <number> [<number> ...] <output variable>)\n"
  65. "REGEX MATCH will match the regular expression once and store the "
  66. "match in the output variable.\n\n"
  67. "REGEX MATCHALL will match the regular expression as many times as "
  68. "possible and store the matches in the output variable as a list.\n\n"
  69. "REGEX REPLACE will match the regular expression as many times as "
  70. "possible and substitute the replacement expression for the match "
  71. "in the output.\n\n"
  72. "COMPARE EQUAL/NOTEQUAL/LESS/GREATER will compare the strings and "
  73. "store true or false in the output variable.\n\n"
  74. "ASCII will convert all numbers into corresponding ASCII characters.";
  75. }
  76. cmTypeMacro(cmStringCommand, cmCommand);
  77. protected:
  78. bool HandleAsciiCommand(std::vector<std::string> const& args);
  79. bool HandleRegexCommand(std::vector<std::string> const& args);
  80. bool RegexMatch(std::vector<std::string> const& args);
  81. bool RegexMatchAll(std::vector<std::string> const& args);
  82. bool RegexReplace(std::vector<std::string> const& args);
  83. bool HandleCompareCommand(std::vector<std::string> const& args);
  84. class RegexReplacement
  85. {
  86. public:
  87. RegexReplacement(const char* s): number(-1), value(s) {}
  88. RegexReplacement(const std::string& s): number(-1), value(s) {}
  89. RegexReplacement(int n): number(n), value() {}
  90. int number;
  91. std::string value;
  92. };
  93. };
  94. #endif