A library for talking to Multi-Tech's Cellular SocketModem Devices.

Dependents:   M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more

Committer:
mfiore
Date:
Thu Dec 19 19:49:58 2013 +0000
Revision:
39:6e94520a3217
Parent:
4:6561c9128c6f
Child:
141:571e0ef6c8dc
add mts namespace to files in cellular/, io/, and utils/ directories; prepend CELL_ to some enums in cellular.h to avoid conflict with HTTPClient class; added AxedaWrapper class for sending data to Axeda backend

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sgodinez 4:6561c9128c6f 1
sgodinez 4:6561c9128c6f 2 #include "MTSText.h"
sgodinez 4:6561c9128c6f 3
mfiore 39:6e94520a3217 4 using namespace mts;
mfiore 39:6e94520a3217 5
sgodinez 4:6561c9128c6f 6 std::string Text::getLine(const std::string& source, const size_t& start, size_t& cursor) {
sgodinez 4:6561c9128c6f 7 char delimiters[2];
sgodinez 4:6561c9128c6f 8 delimiters[0] = '\n';
sgodinez 4:6561c9128c6f 9 delimiters[1] = '\r';
sgodinez 4:6561c9128c6f 10 size_t end = source.find_first_of(delimiters, start, 2);
sgodinez 4:6561c9128c6f 11 std::string line(source.substr(start, end - start));
sgodinez 4:6561c9128c6f 12 if (end < source.size()) {
sgodinez 4:6561c9128c6f 13 if (end < source.size() - 1)
sgodinez 4:6561c9128c6f 14 if ((source[end] == '\n' && source[end + 1] == '\r') || (source[end] == '\r' && source[end + 1] == '\n')) {
sgodinez 4:6561c9128c6f 15 //Advance an additional character in scenarios where lines end in \r\n or \n\r
sgodinez 4:6561c9128c6f 16 end++;
sgodinez 4:6561c9128c6f 17 }
sgodinez 4:6561c9128c6f 18 end++;
sgodinez 4:6561c9128c6f 19 }
sgodinez 4:6561c9128c6f 20 cursor = end;
sgodinez 4:6561c9128c6f 21 return line;
sgodinez 4:6561c9128c6f 22 }
sgodinez 4:6561c9128c6f 23
sgodinez 4:6561c9128c6f 24 std::vector<std::string> Text::split(const std::string& str, char delimiter, int limit) {
sgodinez 4:6561c9128c6f 25 return split(str, std::string(1, delimiter), limit);
sgodinez 4:6561c9128c6f 26 }
sgodinez 4:6561c9128c6f 27
sgodinez 4:6561c9128c6f 28 std::vector<std::string> Text::split(const std::string& str, const std::string& delimiter, int limit) {
sgodinez 4:6561c9128c6f 29 std::vector<std::string> result;
sgodinez 4:6561c9128c6f 30 if(str.size() == 0) {
sgodinez 4:6561c9128c6f 31 return result;
sgodinez 4:6561c9128c6f 32 }
sgodinez 4:6561c9128c6f 33 size_t start = 0;
sgodinez 4:6561c9128c6f 34 size_t end = str.find(delimiter, start);
sgodinez 4:6561c9128c6f 35 for (int i = 1; i < limit || (limit <= 0 && (end != std::string::npos)); ++i) {
sgodinez 4:6561c9128c6f 36 result.push_back(str.substr(start, end - start));
sgodinez 4:6561c9128c6f 37 start = end + delimiter.length();
sgodinez 4:6561c9128c6f 38 end = str.find(delimiter, start);
sgodinez 4:6561c9128c6f 39 }
sgodinez 4:6561c9128c6f 40 result.push_back(str.substr(start));
sgodinez 4:6561c9128c6f 41 return result;
sgodinez 4:6561c9128c6f 42 }