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.

Committer:
Mike Fiore
Date:
Tue Mar 21 15:26:50 2017 -0500
Revision:
15:ae12624eb600
Parent:
14:1d88cf5266c8
update from git revision 37b619a6e4e6e3b49b64c402429cdd8710d960a6

Who changed what in which revision?

UserRevisionLine numberNew 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 14:1d88cf5266c8 56 static std::string float2String(double val, int precision);
Mike Fiore 13:4709c2dfcd11 57
Mike Fiore 15:ae12624eb600 58 static std::string bin2hexString(const std::vector<uint8_t>& data, const char* delim = "", bool leadingZeros = false, bool bytePadding = true);
Mike Fiore 12:7818d55b35c6 59
Mike Fiore 15:ae12624eb600 60 static std::string bin2hexString(const uint8_t* data, const uint32_t len, const char* delim = "", bool leadingZeros = false, bool bytePadding = true);
Mike Fiore 14:1d88cf5266c8 61
Mike Fiore 14:1d88cf5266c8 62 static std::string bin2base64(const std::vector<uint8_t>& data);
Mike Fiore 14:1d88cf5266c8 63
Mike Fiore 14:1d88cf5266c8 64 static std::string bin2base64(const uint8_t* data, size_t size);
Mike Fiore 14:1d88cf5266c8 65
Mike Fiore 14:1d88cf5266c8 66 static bool base642bin(const std::string in, std::vector<uint8_t>& out);
Mike Fiore 13:4709c2dfcd11 67
Mike Fiore 13:4709c2dfcd11 68 static void ltrim(std::string& str, const char* args);
Mike Fiore 13:4709c2dfcd11 69
Mike Fiore 13:4709c2dfcd11 70 static void rtrim(std::string& str, const char* args);
Mike Fiore 13:4709c2dfcd11 71
Mike Fiore 13:4709c2dfcd11 72 static void trim(std::string& str, const char* args);
Mike Fiore 13:4709c2dfcd11 73
Mike Fiore 2:7779ede60c3d 74 private:
Vanger 10:d1a3f03f093f 75 // Safety for class with only static methods
Mike Fiore 2:7779ede60c3d 76 Text();
Mike Fiore 2:7779ede60c3d 77 Text(const Text& other);
Mike Fiore 2:7779ede60c3d 78 Text& operator=(const Text& other);
Mike Fiore 2:7779ede60c3d 79 };
Mike Fiore 2:7779ede60c3d 80
Mike Fiore 2:7779ede60c3d 81 }
Mike Fiore 2:7779ede60c3d 82
Mike Fiore 2:7779ede60c3d 83 #endif