cmStringCommand.h 4.0 KB

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