1 // compat.cc
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // Author: riley@google.com (Michael Riley)
16 //
17 // \file
18 // Google compatibility definitions.
19
20 #include <cstring>
21 #include <fst/compat.h>
22
23 using namespace std;
24
FailedNewHandler()25 void FailedNewHandler() {
26 cerr << "Memory allocation failed\n";
27 exit(1);
28 }
29
30 namespace fst {
31
SplitToVector(char * full,const char * delim,vector<char * > * vec,bool omit_empty_strings)32 void SplitToVector(char* full, const char* delim, vector<char*>* vec,
33 bool omit_empty_strings) {
34 char *p = full;
35 while (p) {
36 if ((p = strpbrk(full, delim)))
37 p[0] = '\0';
38 if (!omit_empty_strings || full[0] != '\0')
39 vec->push_back(full);
40 if (p)
41 full = p + 1;
42 }
43 }
44 } // namespace fst
45