]> Dogcows Code - chaz/yoink/blobdiff - src/stlplus/strings/string_utilities.hpp
testing new non-autotools build system
[chaz/yoink] / src / stlplus / strings / string_utilities.hpp
diff --git a/src/stlplus/strings/string_utilities.hpp b/src/stlplus/strings/string_utilities.hpp
new file mode 100644 (file)
index 0000000..d8d39c4
--- /dev/null
@@ -0,0 +1,120 @@
+#ifndef STLPLUS_STRING_UTILITIES\r
+#define STLPLUS_STRING_UTILITIES\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+//   Author:    Andy Rushton\r
+//   Copyright: (c) Southampton University 1999-2004\r
+//              (c) Andy Rushton           2004-2009\r
+//   License:   BSD License, see ../docs/license.html\r
+\r
+//   Utilities for manipulating std::strings\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+#include "strings_fixes.hpp"\r
+#include "format_types.hpp"\r
+#include <vector>\r
+#include <string>\r
+#include <stdexcept>\r
+#include <time.h>\r
+\r
+namespace stlplus\r
+{\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // Padding function allows a string to be printed in a fixed-width field\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+  // The definitions for the alignment are declared in format_types.hpp\r
+  // Any other value will cause std::invalid_argument to be thrown\r
+\r
+  std::string pad(const std::string& str,\r
+                  alignment_t alignment,\r
+                  unsigned width,\r
+                  char padch = ' ')\r
+    throw(std::invalid_argument);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // whitespace trimming\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+  std::string trim_left(const std::string& val);\r
+  std::string trim_right(const std::string& val);\r
+  std::string trim(const std::string& val);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // case conversion for std::strings\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+  std::string lowercase(const std::string& val);\r
+  std::string uppercase(const std::string& val);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // character translation - inspired by Unix 'tr' command\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+  // convert characters represented in from_set to the characters in the same position in to_set\r
+  // for example:\r
+  //   filename = translate(filename,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ");\r
+  // converts the filename to uppercase and returns the result (Note that the\r
+  // uppercase function does this more easily). If the from_set is longer than\r
+  // the to_set, then the overlap represents characters to delete (i.e. they map\r
+  // to nothing)\r
+\r
+  std::string translate(const std::string& input,\r
+                        const std::string& from_set,\r
+                        const std::string& to_set = std::string());\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // wildcard matching\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+  // this function does wildcard matching of the wildcard expression against the candidate std::string\r
+  // wildcards are NOT regular expressions\r
+  // the wildcard characters are * and ? where * matches 1 or more characters and ? matches only one\r
+  // there are also character sets [a-z] [qwertyuiop] etc. which match 1 character\r
+  // TODO: character sets like [:alpha:]\r
+  // TODO eventually: regular expression matching and substitution (3rd party library?)\r
+\r
+  bool match_wildcard(const std::string& wild,\r
+                      const std::string& match);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // Perl-inspired split/join functions\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+  // splits the string at every occurance of splitter and adds it as a separate string to the return value\r
+  // the splitter is removed\r
+  // a string with no splitter in it will give a single-value vector\r
+  // an empty string gives an empty vector\r
+\r
+  std::vector<std::string> split (const std::string& str,\r
+                                  const std::string& splitter = "\n");\r
+\r
+  // the reverse of the above\r
+  // joins the string vector to create a single string with the joiner inserted between the joins\r
+  // Note: the joiner will not be added at the beginning or the end\r
+  // However, there are optional fields to add such prefix and suffix strings\r
+\r
+  std::string join (const std::vector<std::string>&,\r
+                    const std::string& joiner = "\n",\r
+                    const std::string& prefix = "",\r
+                    const std::string& suffix = "");\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // special displays\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+  // display the parameter as a number in bytes, kbytes, Mbytes, Gbytes depending on range\r
+\r
+  std::string display_bytes(long bytes);\r
+\r
+  // display the parameter in seconds as a string representation in weeks, days, hours, minutes, seconds\r
+  // e.g. "1d 1:01:01" means 1 day, 1 hour, 1 minute and 1 second\r
+\r
+  std::string display_time(time_t seconds);\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+\r
+} // end namespace stlplus\r
+\r
+#endif\r
This page took 0.025943 seconds and 4 git commands to generate.