blob: f5c9d8ef7242d6d606d8c240288730463bf48107 [file] [log] [blame]
Matt Sharifibda09f12017-03-10 12:29:15 +01001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "common/utils.h"
18
19#include <ctype.h>
20#include <stdlib.h>
21
22namespace libtextclassifier {
23namespace nlp_core {
24namespace utils {
25
26std::string TrimString(const std::string &text) {
27 int start = 0;
28 while ((start < text.size()) && isspace(text[start])) {
29 start++;
30 }
31 int end = text.size() - 1;
32 while ((end > start) && isspace(text[end])) {
33 end--;
34 }
35 return text.substr(start, end - start + 1);
36}
37
38std::string Lowercase(const std::string &s) {
39 std::string result(s);
40 for (char &c : result) {
41 c = tolower(c);
42 }
43 return result;
44}
45
46void NormalizeDigits(std::string *form) {
47 for (size_t i = 0; i < form->size(); ++i) {
48 if ((*form)[i] >= '0' && (*form)[i] <= '9') {
49 (*form)[i] = '9';
50 }
51 }
52}
53
54} // namespace utils
55} // namespace nlp_core
56} // namespace libtextclassifier