Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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@13:4709c2dfcd11, 2015-06-08 (annotated)
- Committer:
- Mike Fiore
- Date:
- Mon Jun 08 15:30:12 2015 -0500
- Revision:
- 13:4709c2dfcd11
- Parent:
- 12:7818d55b35c6
- Child:
- 14:1d88cf5266c8
update to 25a04c8ca1d5f2d503bf327e58caa949b8f1778a of internal repo
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 |
13:4709c2dfcd11 | 7 | #include <stdint.h> |
| Mike Fiore |
13:4709c2dfcd11 | 8 | #include <stdio.h> |
| Mike Fiore |
13:4709c2dfcd11 | 9 | #include <string.h> |
| Mike Fiore |
2:7779ede60c3d | 10 | |
| Mike Fiore |
2:7779ede60c3d | 11 | namespace mts |
| Mike Fiore |
2:7779ede60c3d | 12 | { |
| Mike Fiore |
2:7779ede60c3d | 13 | |
| Mike Fiore |
2:7779ede60c3d | 14 | /** This class contains a number of static methods for manipulating strings and other |
| Mike Fiore |
2:7779ede60c3d | 15 | * text data. |
| Mike Fiore |
2:7779ede60c3d | 16 | */ |
| Mike Fiore |
2:7779ede60c3d | 17 | class Text |
| Mike Fiore |
2:7779ede60c3d | 18 | { |
| Mike Fiore |
2:7779ede60c3d | 19 | public: |
| Mike Fiore |
2:7779ede60c3d | 20 | /** This static method can be used to pull out a string at the next line break. A |
| Mike Fiore |
2:7779ede60c3d | 21 | * break can either be a newline '\n', carriage return '\r' or both. |
| Mike Fiore |
2:7779ede60c3d | 22 | * |
| Mike Fiore |
2:7779ede60c3d | 23 | * @param source the source string to look for the line break on. |
| Mike Fiore |
2:7779ede60c3d | 24 | * @param start the start postion within the string to begin looking for the line |
| Mike Fiore |
2:7779ede60c3d | 25 | * break. |
| Mike Fiore |
2:7779ede60c3d | 26 | * @param cursor this value will be updated with the index for the next available character |
| Mike Fiore |
2:7779ede60c3d | 27 | * after the line break. If a line break is not found returns -1. |
| Mike Fiore |
2:7779ede60c3d | 28 | * @returns the string beginning with the start index up to including the line breaks. |
| Mike Fiore |
2:7779ede60c3d | 29 | */ |
| Mike Fiore |
2:7779ede60c3d | 30 | static std::string getLine(const std::string& source, const size_t& start, size_t& cursor); |
| Mike Fiore |
2:7779ede60c3d | 31 | |
| Mike Fiore |
2:7779ede60c3d | 32 | /** This is a static method for splitting strings using a delimeter value. |
| Mike Fiore |
2:7779ede60c3d | 33 | * |
| Mike Fiore |
2:7779ede60c3d | 34 | * @param str the string to try and split. |
| Mike Fiore |
2:7779ede60c3d | 35 | * @param delimiter the delimeter value to split on as a character. |
| Mike Fiore |
2:7779ede60c3d | 36 | * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible. |
| Mike Fiore |
2:7779ede60c3d | 37 | * The default is 0. |
| Mike Fiore |
2:7779ede60c3d | 38 | * @returns an ordered vector of strings conatining the splits of the original string. |
| Mike Fiore |
2:7779ede60c3d | 39 | */ |
| Mike Fiore |
2:7779ede60c3d | 40 | static std::vector<std::string> split(const std::string& str, char delimiter, int limit = 0); |
| Mike Fiore |
2:7779ede60c3d | 41 | |
| Mike Fiore |
2:7779ede60c3d | 42 | /** This is a static method for splitting strings using a delimeter value. |
| Mike Fiore |
2:7779ede60c3d | 43 | * |
| Mike Fiore |
2:7779ede60c3d | 44 | * @param str the string to try and split. |
| Mike Fiore |
2:7779ede60c3d | 45 | * @param delimiter the delimeter value to split on as a string. |
| Mike Fiore |
2:7779ede60c3d | 46 | * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible. |
| Mike Fiore |
2:7779ede60c3d | 47 | * The default is 0. |
| Mike Fiore |
2:7779ede60c3d | 48 | * @returns an ordered vector of strings conatining the splits of the original string. |
| Mike Fiore |
2:7779ede60c3d | 49 | */ |
| Mike Fiore |
2:7779ede60c3d | 50 | static std::vector<std::string> split(const std::string& str, const std::string& delimiter, int limit = 0); |
| Mike Fiore |
2:7779ede60c3d | 51 | |
| Mike Fiore |
2:7779ede60c3d | 52 | static std::string readString(char* index, int length); |
| Mike Fiore |
2:7779ede60c3d | 53 | |
| Mike Fiore |
12:7818d55b35c6 | 54 | static std::string toUpper(const std::string str); |
| Mike Fiore |
13:4709c2dfcd11 | 55 | |
| Mike Fiore |
13:4709c2dfcd11 | 56 | std::string float2String(double val, int precision); |
| Mike Fiore |
13:4709c2dfcd11 | 57 | |
| Mike Fiore |
13:4709c2dfcd11 | 58 | static std::string bin2hexString(const std::vector<uint8_t>& data, const char* delim = "", bool leadingZeros = false); |
| Mike Fiore |
12:7818d55b35c6 | 59 | |
| Mike Fiore |
13:4709c2dfcd11 | 60 | static std::string bin2hexString(const uint8_t* data, const uint32_t len, const char* delim = "", bool leadingZeros = false); |
| Mike Fiore |
13:4709c2dfcd11 | 61 | |
| Mike Fiore |
13:4709c2dfcd11 | 62 | static void ltrim(std::string& str, const char* args); |
| Mike Fiore |
13:4709c2dfcd11 | 63 | |
| Mike Fiore |
13:4709c2dfcd11 | 64 | static void rtrim(std::string& str, const char* args); |
| Mike Fiore |
13:4709c2dfcd11 | 65 | |
| Mike Fiore |
13:4709c2dfcd11 | 66 | static void trim(std::string& str, const char* args); |
| Mike Fiore |
13:4709c2dfcd11 | 67 | |
| Mike Fiore |
2:7779ede60c3d | 68 | private: |
| Vanger | 10:d1a3f03f093f | 69 | // Safety for class with only static methods |
| Mike Fiore |
2:7779ede60c3d | 70 | Text(); |
| Mike Fiore |
2:7779ede60c3d | 71 | Text(const Text& other); |
| Mike Fiore |
2:7779ede60c3d | 72 | Text& operator=(const Text& other); |
| Mike Fiore |
2:7779ede60c3d | 73 | }; |
| Mike Fiore |
2:7779ede60c3d | 74 | |
| Mike Fiore |
2:7779ede60c3d | 75 | } |
| Mike Fiore |
2:7779ede60c3d | 76 | |
| Mike Fiore |
2:7779ede60c3d | 77 | #endif |