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:
Mon May 19 12:37:38 2014 -0500
Revision:
4:f4d3bafc71dd
Parent:
2:7779ede60c3d
Child:
6:fca9bc67b15f
remove "mbed.h" from cpp files, add to headers

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 4:f4d3bafc71dd 4 #include "mbed.h"
Mike Fiore 2:7779ede60c3d 5 #include <string>
Mike Fiore 2:7779ede60c3d 6 #include <vector>
Mike Fiore 2:7779ede60c3d 7 #include <stddef.h>
Mike Fiore 2:7779ede60c3d 8
Mike Fiore 2:7779ede60c3d 9 namespace mts
Mike Fiore 2:7779ede60c3d 10 {
Mike Fiore 2:7779ede60c3d 11
Mike Fiore 2:7779ede60c3d 12 /** This class contains a number of static methods for manipulating strings and other
Mike Fiore 2:7779ede60c3d 13 * text data.
Mike Fiore 2:7779ede60c3d 14 */
Mike Fiore 2:7779ede60c3d 15 class Text
Mike Fiore 2:7779ede60c3d 16 {
Mike Fiore 2:7779ede60c3d 17 public:
Mike Fiore 2:7779ede60c3d 18 /** This static method can be used to pull out a string at the next line break. A
Mike Fiore 2:7779ede60c3d 19 * break can either be a newline '\n', carriage return '\r' or both.
Mike Fiore 2:7779ede60c3d 20 *
Mike Fiore 2:7779ede60c3d 21 * @param source the source string to look for the line break on.
Mike Fiore 2:7779ede60c3d 22 * @param start the start postion within the string to begin looking for the line
Mike Fiore 2:7779ede60c3d 23 * break.
Mike Fiore 2:7779ede60c3d 24 * @param cursor this value will be updated with the index for the next available character
Mike Fiore 2:7779ede60c3d 25 * after the line break. If a line break is not found returns -1.
Mike Fiore 2:7779ede60c3d 26 * @returns the string beginning with the start index up to including the line breaks.
Mike Fiore 2:7779ede60c3d 27 */
Mike Fiore 2:7779ede60c3d 28 static std::string getLine(const std::string& source, const size_t& start, size_t& cursor);
Mike Fiore 2:7779ede60c3d 29
Mike Fiore 2:7779ede60c3d 30 /** This is a static method for splitting strings using a delimeter value.
Mike Fiore 2:7779ede60c3d 31 *
Mike Fiore 2:7779ede60c3d 32 * @param str the string to try and split.
Mike Fiore 2:7779ede60c3d 33 * @param delimiter the delimeter value to split on as a character.
Mike Fiore 2:7779ede60c3d 34 * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible.
Mike Fiore 2:7779ede60c3d 35 * The default is 0.
Mike Fiore 2:7779ede60c3d 36 * @returns an ordered vector of strings conatining the splits of the original string.
Mike Fiore 2:7779ede60c3d 37 */
Mike Fiore 2:7779ede60c3d 38 static std::vector<std::string> split(const std::string& str, char delimiter, int limit = 0);
Mike Fiore 2:7779ede60c3d 39
Mike Fiore 2:7779ede60c3d 40 /** This is a static method for splitting strings using a delimeter value.
Mike Fiore 2:7779ede60c3d 41 *
Mike Fiore 2:7779ede60c3d 42 * @param str the string to try and split.
Mike Fiore 2:7779ede60c3d 43 * @param delimiter the delimeter value to split on as a string.
Mike Fiore 2:7779ede60c3d 44 * @param limit the maximum number of splits. If equal to 0 it splits as amny times as possible.
Mike Fiore 2:7779ede60c3d 45 * The default is 0.
Mike Fiore 2:7779ede60c3d 46 * @returns an ordered vector of strings conatining the splits of the original string.
Mike Fiore 2:7779ede60c3d 47 */
Mike Fiore 2:7779ede60c3d 48 static std::vector<std::string> split(const std::string& str, const std::string& delimiter, int limit = 0);
Mike Fiore 2:7779ede60c3d 49
Mike Fiore 2:7779ede60c3d 50 static std::string readString(char* index, int length);
Mike Fiore 2:7779ede60c3d 51
Mike Fiore 2:7779ede60c3d 52 private:
Mike Fiore 2:7779ede60c3d 53 // Saftey for class with only static methods
Mike Fiore 2:7779ede60c3d 54 Text();
Mike Fiore 2:7779ede60c3d 55 Text(const Text& other);
Mike Fiore 2:7779ede60c3d 56 Text& operator=(const Text& other);
Mike Fiore 2:7779ede60c3d 57 };
Mike Fiore 2:7779ede60c3d 58
Mike Fiore 2:7779ede60c3d 59 }
Mike Fiore 2:7779ede60c3d 60
Mike Fiore 2:7779ede60c3d 61 #endif