1 // Copyright 2017 The Abseil Authors.
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 // This file contains functions that remove a defined part from the string,
16 // i.e., strip the string.
17 
18 #include "s2/third_party/absl/strings/strip.h"
19 
20 #include "s2/third_party/absl/strings/string_view.h"
21 
22 // ----------------------------------------------------------------------
23 // ReplaceCharacters
24 //    Replaces any occurrence of any of the 'remove' *bytes*
25 //    with the 'replace_with' *byte*.
26 // ----------------------------------------------------------------------
ReplaceCharacters(char * str,size_t len,absl::string_view remove,char replace_with)27 void ReplaceCharacters(char* str, size_t len, absl::string_view remove,
28                        char replace_with) {
29   for (char* end = str + len; str != end; ++str) {
30     if (remove.find(*str) != absl::string_view::npos) {
31       *str = replace_with;
32     }
33   }
34 }
35 
ReplaceCharacters(string * s,absl::string_view remove,char replace_with)36 void ReplaceCharacters(string* s, absl::string_view remove, char replace_with) {
37   for (char& ch : *s) {
38     if (remove.find(ch) != absl::string_view::npos) {
39       ch = replace_with;
40     }
41   }
42 }
43