Axeda Ready Demo for Freescale FRDM-KL46Z as accident alert system

Dependencies:   FRDM_MMA8451Q KL46Z-USBHost MAG3110 SocketModem TSI mbed FATFileSystem

Fork of AxedaGo-Freescal_FRDM-KL46Z by Axeda Corp

Committer:
AxedaCorp
Date:
Tue Jul 01 21:31:54 2014 +0000
Revision:
0:65004368569c
Made initial

Who changed what in which revision?

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