libmDot 1.0.12-hotfix
MTS-Utils/MTSText.h@0:5f84bdd949b8, 2016-07-17 (annotated)
- Committer:
- shaunkrnelson
- Date:
- Sun Jul 17 00:03:03 2016 +0000
- Revision:
- 0:5f84bdd949b8
1.0.12-hotfix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shaunkrnelson | 0:5f84bdd949b8 | 1 | #ifndef MTSTEXT_H |
shaunkrnelson | 0:5f84bdd949b8 | 2 | #define MTSTEXT_H |
shaunkrnelson | 0:5f84bdd949b8 | 3 | |
shaunkrnelson | 0:5f84bdd949b8 | 4 | #include <string> |
shaunkrnelson | 0:5f84bdd949b8 | 5 | #include <vector> |
shaunkrnelson | 0:5f84bdd949b8 | 6 | #include <stddef.h> |
shaunkrnelson | 0:5f84bdd949b8 | 7 | #include <stdint.h> |
shaunkrnelson | 0:5f84bdd949b8 | 8 | #include <stdio.h> |
shaunkrnelson | 0:5f84bdd949b8 | 9 | #include <string.h> |
shaunkrnelson | 0:5f84bdd949b8 | 10 | |
shaunkrnelson | 0:5f84bdd949b8 | 11 | namespace mts |
shaunkrnelson | 0:5f84bdd949b8 | 12 | { |
shaunkrnelson | 0:5f84bdd949b8 | 13 | |
shaunkrnelson | 0:5f84bdd949b8 | 14 | /** This class contains a number of static methods for manipulating strings and other |
shaunkrnelson | 0:5f84bdd949b8 | 15 | * text data. |
shaunkrnelson | 0:5f84bdd949b8 | 16 | */ |
shaunkrnelson | 0:5f84bdd949b8 | 17 | class Text |
shaunkrnelson | 0:5f84bdd949b8 | 18 | { |
shaunkrnelson | 0:5f84bdd949b8 | 19 | public: |
shaunkrnelson | 0:5f84bdd949b8 | 20 | /** This static method can be used to pull out a string at the next line break. A |
shaunkrnelson | 0:5f84bdd949b8 | 21 | * break can either be a newline '\n', carriage return '\r' or both. |
shaunkrnelson | 0:5f84bdd949b8 | 22 | * |
shaunkrnelson | 0:5f84bdd949b8 | 23 | * @param source the source string to look for the line break on. |
shaunkrnelson | 0:5f84bdd949b8 | 24 | * @param start the start postion within the string to begin looking for the line |
shaunkrnelson | 0:5f84bdd949b8 | 25 | * break. |
shaunkrnelson | 0:5f84bdd949b8 | 26 | * @param cursor this value will be updated with the index for the next available character |
shaunkrnelson | 0:5f84bdd949b8 | 27 | * after the line break. If a line break is not found returns -1. |
shaunkrnelson | 0:5f84bdd949b8 | 28 | * @returns the string beginning with the start index up to including the line breaks. |
shaunkrnelson | 0:5f84bdd949b8 | 29 | */ |
shaunkrnelson | 0:5f84bdd949b8 | 30 | static std::string getLine(const std::string& source, const size_t& start, size_t& cursor); |
shaunkrnelson | 0:5f84bdd949b8 | 31 | |
shaunkrnelson | 0:5f84bdd949b8 | 32 | /** This is a static method for splitting strings using a delimeter value. |
shaunkrnelson | 0:5f84bdd949b8 | 33 | * |
shaunkrnelson | 0:5f84bdd949b8 | 34 | * @param str the string to try and split. |
shaunkrnelson | 0:5f84bdd949b8 | 35 | * @param delimiter the delimeter value to split on as a character. |
shaunkrnelson | 0:5f84bdd949b8 | 36 | * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible. |
shaunkrnelson | 0:5f84bdd949b8 | 37 | * The default is 0. |
shaunkrnelson | 0:5f84bdd949b8 | 38 | * @returns an ordered vector of strings conatining the splits of the original string. |
shaunkrnelson | 0:5f84bdd949b8 | 39 | */ |
shaunkrnelson | 0:5f84bdd949b8 | 40 | static std::vector<std::string> split(const std::string& str, char delimiter, int limit = 0); |
shaunkrnelson | 0:5f84bdd949b8 | 41 | |
shaunkrnelson | 0:5f84bdd949b8 | 42 | /** This is a static method for splitting strings using a delimeter value. |
shaunkrnelson | 0:5f84bdd949b8 | 43 | * |
shaunkrnelson | 0:5f84bdd949b8 | 44 | * @param str the string to try and split. |
shaunkrnelson | 0:5f84bdd949b8 | 45 | * @param delimiter the delimeter value to split on as a string. |
shaunkrnelson | 0:5f84bdd949b8 | 46 | * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible. |
shaunkrnelson | 0:5f84bdd949b8 | 47 | * The default is 0. |
shaunkrnelson | 0:5f84bdd949b8 | 48 | * @returns an ordered vector of strings conatining the splits of the original string. |
shaunkrnelson | 0:5f84bdd949b8 | 49 | */ |
shaunkrnelson | 0:5f84bdd949b8 | 50 | static std::vector<std::string> split(const std::string& str, const std::string& delimiter, int limit = 0); |
shaunkrnelson | 0:5f84bdd949b8 | 51 | |
shaunkrnelson | 0:5f84bdd949b8 | 52 | static std::string readString(char* index, int length); |
shaunkrnelson | 0:5f84bdd949b8 | 53 | |
shaunkrnelson | 0:5f84bdd949b8 | 54 | static std::string toUpper(const std::string str); |
shaunkrnelson | 0:5f84bdd949b8 | 55 | |
shaunkrnelson | 0:5f84bdd949b8 | 56 | static std::string float2String(double val, int precision); |
shaunkrnelson | 0:5f84bdd949b8 | 57 | |
shaunkrnelson | 0:5f84bdd949b8 | 58 | static std::string bin2hexString(const std::vector<uint8_t>& data, const char* delim = "", bool leadingZeros = false, bool bytePadding = true); |
shaunkrnelson | 0:5f84bdd949b8 | 59 | |
shaunkrnelson | 0:5f84bdd949b8 | 60 | static std::string bin2hexString(const uint8_t* data, const uint32_t len, const char* delim = "", bool leadingZeros = false, bool bytePadding = true); |
shaunkrnelson | 0:5f84bdd949b8 | 61 | |
shaunkrnelson | 0:5f84bdd949b8 | 62 | static std::string bin2base64(const std::vector<uint8_t>& data); |
shaunkrnelson | 0:5f84bdd949b8 | 63 | |
shaunkrnelson | 0:5f84bdd949b8 | 64 | static std::string bin2base64(const uint8_t* data, size_t size); |
shaunkrnelson | 0:5f84bdd949b8 | 65 | |
shaunkrnelson | 0:5f84bdd949b8 | 66 | static bool base642bin(const std::string in, std::vector<uint8_t>& out); |
shaunkrnelson | 0:5f84bdd949b8 | 67 | |
shaunkrnelson | 0:5f84bdd949b8 | 68 | static void ltrim(std::string& str, const char* args); |
shaunkrnelson | 0:5f84bdd949b8 | 69 | |
shaunkrnelson | 0:5f84bdd949b8 | 70 | static void rtrim(std::string& str, const char* args); |
shaunkrnelson | 0:5f84bdd949b8 | 71 | |
shaunkrnelson | 0:5f84bdd949b8 | 72 | static void trim(std::string& str, const char* args); |
shaunkrnelson | 0:5f84bdd949b8 | 73 | |
shaunkrnelson | 0:5f84bdd949b8 | 74 | private: |
shaunkrnelson | 0:5f84bdd949b8 | 75 | // Safety for class with only static methods |
shaunkrnelson | 0:5f84bdd949b8 | 76 | Text(); |
shaunkrnelson | 0:5f84bdd949b8 | 77 | Text(const Text& other); |
shaunkrnelson | 0:5f84bdd949b8 | 78 | Text& operator=(const Text& other); |
shaunkrnelson | 0:5f84bdd949b8 | 79 | }; |
shaunkrnelson | 0:5f84bdd949b8 | 80 | |
shaunkrnelson | 0:5f84bdd949b8 | 81 | } |
shaunkrnelson | 0:5f84bdd949b8 | 82 | |
shaunkrnelson | 0:5f84bdd949b8 | 83 | #endif |