cmStringCommand.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. * This determines if the command gets propagated down
  38. * to makefiles located in subdirectories.
  39. */
  40. virtual bool IsInherited() {return true;}
  41. /**
  42. * The name of the command as specified in CMakeList.txt.
  43. */
  44. virtual const char* GetName() { return "STRING";}
  45. /**
  46. * Succinct documentation.
  47. */
  48. virtual const char* GetTerseDocumentation()
  49. {
  50. return "String operations.";
  51. }
  52. /**
  53. * More documentation.
  54. */
  55. virtual const char* GetFullDocumentation()
  56. {
  57. return
  58. " STRING(REGEX MATCH <regular_expression>\n"
  59. " <output variable> <input> [<input>...])\n"
  60. " STRING(REGEX MATCHALL <regular_expression>\n"
  61. " <output variable> <input> [<input>...])\n"
  62. " STRING(REGEX REPLACE <regular_expression>\n"
  63. " <replace_expression> <output variable>\n"
  64. " <input> [<input>...])\n"
  65. " STRING(COMPARE EQUAL <string1> <string2> <output variable>)\n"
  66. " STRING(COMPARE NOTEQUAL <string1> <string2> <output variable>)\n"
  67. " STRING(COMPARE LESS <string1> <string2> <output variable>)\n"
  68. " STRING(COMPARE GREATER <string1> <string2> <output variable>)\n"
  69. " STRING(ASCII <number> [<number> ...] <output variable>)\n"
  70. "REGEX MATCH will match the regular expression once and store the "
  71. "match in the output variable.\n"
  72. "REGEX MATCHALL will match the regular expression as many times as "
  73. "possible and store the matches in the output variable as a list.\n"
  74. "REGEX REPLACE will match the regular expression as many times as "
  75. "possible and substitute the replacement expression for the match "
  76. "in the output.\n"
  77. "COMPARE EQUAL/NOTEQUAL/LESS/GREATER will compare the strings and "
  78. "store true or false in the output variable.\n"
  79. "ASCII will convert all numbers into corresponding ASCII characters.";
  80. }
  81. cmTypeMacro(cmStringCommand, cmCommand);
  82. protected:
  83. bool HandleAsciiCommand(std::vector<std::string> const& args);
  84. bool HandleRegexCommand(std::vector<std::string> const& args);
  85. bool RegexMatch(std::vector<std::string> const& args);
  86. bool RegexMatchAll(std::vector<std::string> const& args);
  87. bool RegexReplace(std::vector<std::string> const& args);
  88. bool HandleCompareCommand(std::vector<std::string> const& args);
  89. class RegexReplacement
  90. {
  91. public:
  92. RegexReplacement(const char* s): number(-1), value(s) {}
  93. RegexReplacement(const std::string& s): number(-1), value(s) {}
  94. RegexReplacement(int n): number(n), value() {}
  95. int number;
  96. std::string value;
  97. };
  98. };
  99. #endif