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