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:
kranjan
Date:
Sat Jan 04 05:28:45 2014 +0000
Revision:
141:571e0ef6c8dc
Parent:
39:6e94520a3217
Added licensing header to all files in the library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kranjan 141:571e0ef6c8dc 1 /* Universal Socket Modem Interface Library
kranjan 141:571e0ef6c8dc 2 * Copyright (c) 2013 Multi-Tech Systems
kranjan 141:571e0ef6c8dc 3 *
kranjan 141:571e0ef6c8dc 4 * Licensed under the Apache License, Version 2.0 (the "License");
kranjan 141:571e0ef6c8dc 5 * you may not use this file except in compliance with the License.
kranjan 141:571e0ef6c8dc 6 * You may obtain a copy of the License at
kranjan 141:571e0ef6c8dc 7 *
kranjan 141:571e0ef6c8dc 8 * http://www.apache.org/licenses/LICENSE-2.0
kranjan 141:571e0ef6c8dc 9 *
kranjan 141:571e0ef6c8dc 10 * Unless required by applicable law or agreed to in writing, software
kranjan 141:571e0ef6c8dc 11 * distributed under the License is distributed on an "AS IS" BASIS,
kranjan 141:571e0ef6c8dc 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kranjan 141:571e0ef6c8dc 13 * See the License for the specific language governing permissions and
kranjan 141:571e0ef6c8dc 14 * limitations under the License.
kranjan 141:571e0ef6c8dc 15 */
sgodinez 4:6561c9128c6f 16
sgodinez 4:6561c9128c6f 17 #include "MTSText.h"
sgodinez 4:6561c9128c6f 18
mfiore 39:6e94520a3217 19 using namespace mts;
mfiore 39:6e94520a3217 20
sgodinez 4:6561c9128c6f 21 std::string Text::getLine(const std::string& source, const size_t& start, size_t& cursor) {
sgodinez 4:6561c9128c6f 22 char delimiters[2];
sgodinez 4:6561c9128c6f 23 delimiters[0] = '\n';
sgodinez 4:6561c9128c6f 24 delimiters[1] = '\r';
sgodinez 4:6561c9128c6f 25 size_t end = source.find_first_of(delimiters, start, 2);
sgodinez 4:6561c9128c6f 26 std::string line(source.substr(start, end - start));
sgodinez 4:6561c9128c6f 27 if (end < source.size()) {
sgodinez 4:6561c9128c6f 28 if (end < source.size() - 1)
sgodinez 4:6561c9128c6f 29 if ((source[end] == '\n' && source[end + 1] == '\r') || (source[end] == '\r' && source[end + 1] == '\n')) {
sgodinez 4:6561c9128c6f 30 //Advance an additional character in scenarios where lines end in \r\n or \n\r
sgodinez 4:6561c9128c6f 31 end++;
sgodinez 4:6561c9128c6f 32 }
sgodinez 4:6561c9128c6f 33 end++;
sgodinez 4:6561c9128c6f 34 }
sgodinez 4:6561c9128c6f 35 cursor = end;
sgodinez 4:6561c9128c6f 36 return line;
sgodinez 4:6561c9128c6f 37 }
sgodinez 4:6561c9128c6f 38
sgodinez 4:6561c9128c6f 39 std::vector<std::string> Text::split(const std::string& str, char delimiter, int limit) {
sgodinez 4:6561c9128c6f 40 return split(str, std::string(1, delimiter), limit);
sgodinez 4:6561c9128c6f 41 }
sgodinez 4:6561c9128c6f 42
sgodinez 4:6561c9128c6f 43 std::vector<std::string> Text::split(const std::string& str, const std::string& delimiter, int limit) {
sgodinez 4:6561c9128c6f 44 std::vector<std::string> result;
sgodinez 4:6561c9128c6f 45 if(str.size() == 0) {
sgodinez 4:6561c9128c6f 46 return result;
sgodinez 4:6561c9128c6f 47 }
sgodinez 4:6561c9128c6f 48 size_t start = 0;
sgodinez 4:6561c9128c6f 49 size_t end = str.find(delimiter, start);
sgodinez 4:6561c9128c6f 50 for (int i = 1; i < limit || (limit <= 0 && (end != std::string::npos)); ++i) {
sgodinez 4:6561c9128c6f 51 result.push_back(str.substr(start, end - start));
sgodinez 4:6561c9128c6f 52 start = end + delimiter.length();
sgodinez 4:6561c9128c6f 53 end = str.find(delimiter, start);
sgodinez 4:6561c9128c6f 54 }
sgodinez 4:6561c9128c6f 55 result.push_back(str.substr(start));
sgodinez 4:6561c9128c6f 56 return result;
sgodinez 4:6561c9128c6f 57 }
kranjan 141:571e0ef6c8dc 58