Utility library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems
Dependents: mtsas mtsas thermostat_fan_demo--fan mtsas ... more
NOTE: MTS-Utils has moved to GitHub. This version will not be updated. For updates, go to the GitHub version.
MTSText.h@10:d1a3f03f093f, 2014-07-16 (annotated)
- Committer:
- Vanger
- Date:
- Wed Jul 16 14:24:00 2014 +0000
- Revision:
- 10:d1a3f03f093f
- Parent:
- 6:fca9bc67b15f
- Child:
- 12:7818d55b35c6
Spelling fix on the word safety under MTSText.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:db0490588bc7 | 1 | #ifndef MTSTEXT_H |
mfiore | 0:db0490588bc7 | 2 | #define MTSTEXT_H |
mfiore | 0:db0490588bc7 | 3 | |
Mike Fiore |
2:7779ede60c3d | 4 | #include <string> |
Mike Fiore |
2:7779ede60c3d | 5 | #include <vector> |
Mike Fiore |
2:7779ede60c3d | 6 | #include <stddef.h> |
Mike Fiore |
2:7779ede60c3d | 7 | |
Mike Fiore |
2:7779ede60c3d | 8 | namespace mts |
Mike Fiore |
2:7779ede60c3d | 9 | { |
Mike Fiore |
2:7779ede60c3d | 10 | |
Mike Fiore |
2:7779ede60c3d | 11 | /** This class contains a number of static methods for manipulating strings and other |
Mike Fiore |
2:7779ede60c3d | 12 | * text data. |
Mike Fiore |
2:7779ede60c3d | 13 | */ |
Mike Fiore |
2:7779ede60c3d | 14 | class Text |
Mike Fiore |
2:7779ede60c3d | 15 | { |
Mike Fiore |
2:7779ede60c3d | 16 | public: |
Mike Fiore |
2:7779ede60c3d | 17 | /** This static method can be used to pull out a string at the next line break. A |
Mike Fiore |
2:7779ede60c3d | 18 | * break can either be a newline '\n', carriage return '\r' or both. |
Mike Fiore |
2:7779ede60c3d | 19 | * |
Mike Fiore |
2:7779ede60c3d | 20 | * @param source the source string to look for the line break on. |
Mike Fiore |
2:7779ede60c3d | 21 | * @param start the start postion within the string to begin looking for the line |
Mike Fiore |
2:7779ede60c3d | 22 | * break. |
Mike Fiore |
2:7779ede60c3d | 23 | * @param cursor this value will be updated with the index for the next available character |
Mike Fiore |
2:7779ede60c3d | 24 | * after the line break. If a line break is not found returns -1. |
Mike Fiore |
2:7779ede60c3d | 25 | * @returns the string beginning with the start index up to including the line breaks. |
Mike Fiore |
2:7779ede60c3d | 26 | */ |
Mike Fiore |
2:7779ede60c3d | 27 | static std::string getLine(const std::string& source, const size_t& start, size_t& cursor); |
Mike Fiore |
2:7779ede60c3d | 28 | |
Mike Fiore |
2:7779ede60c3d | 29 | /** This is a static method for splitting strings using a delimeter value. |
Mike Fiore |
2:7779ede60c3d | 30 | * |
Mike Fiore |
2:7779ede60c3d | 31 | * @param str the string to try and split. |
Mike Fiore |
2:7779ede60c3d | 32 | * @param delimiter the delimeter value to split on as a character. |
Mike Fiore |
2:7779ede60c3d | 33 | * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible. |
Mike Fiore |
2:7779ede60c3d | 34 | * The default is 0. |
Mike Fiore |
2:7779ede60c3d | 35 | * @returns an ordered vector of strings conatining the splits of the original string. |
Mike Fiore |
2:7779ede60c3d | 36 | */ |
Mike Fiore |
2:7779ede60c3d | 37 | static std::vector<std::string> split(const std::string& str, char delimiter, int limit = 0); |
Mike Fiore |
2:7779ede60c3d | 38 | |
Mike Fiore |
2:7779ede60c3d | 39 | /** This is a static method for splitting strings using a delimeter value. |
Mike Fiore |
2:7779ede60c3d | 40 | * |
Mike Fiore |
2:7779ede60c3d | 41 | * @param str the string to try and split. |
Mike Fiore |
2:7779ede60c3d | 42 | * @param delimiter the delimeter value to split on as a string. |
Mike Fiore |
2:7779ede60c3d | 43 | * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible. |
Mike Fiore |
2:7779ede60c3d | 44 | * The default is 0. |
Mike Fiore |
2:7779ede60c3d | 45 | * @returns an ordered vector of strings conatining the splits of the original string. |
Mike Fiore |
2:7779ede60c3d | 46 | */ |
Mike Fiore |
2:7779ede60c3d | 47 | static std::vector<std::string> split(const std::string& str, const std::string& delimiter, int limit = 0); |
Mike Fiore |
2:7779ede60c3d | 48 | |
Mike Fiore |
2:7779ede60c3d | 49 | static std::string readString(char* index, int length); |
Mike Fiore |
2:7779ede60c3d | 50 | |
Mike Fiore |
2:7779ede60c3d | 51 | private: |
Vanger | 10:d1a3f03f093f | 52 | // Safety for class with only static methods |
Mike Fiore |
2:7779ede60c3d | 53 | Text(); |
Mike Fiore |
2:7779ede60c3d | 54 | Text(const Text& other); |
Mike Fiore |
2:7779ede60c3d | 55 | Text& operator=(const Text& other); |
Mike Fiore |
2:7779ede60c3d | 56 | }; |
Mike Fiore |
2:7779ede60c3d | 57 | |
Mike Fiore |
2:7779ede60c3d | 58 | } |
Mike Fiore |
2:7779ede60c3d | 59 | |
Mike Fiore |
2:7779ede60c3d | 60 | #endif |