tlx
union_words.cpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* tlx/string/union_words.cpp
3
*
4
* Part of tlx - http://panthema.net/tlx
5
*
6
* Copyright (C) 2016-2017 Timo Bingmann <tb@panthema.net>
7
*
8
* All rights reserved. Published under the Boost Software License, Version 1.0
9
******************************************************************************/
10
11
#include <
tlx/string/contains_word.hpp
>
12
#include <
tlx/string/union_words.hpp
>
13
14
namespace
tlx
{
15
16
std::string
union_words
(
const
std::string& wordsA,
const
std::string& wordsB) {
17
std::string words = wordsA;
18
19
std::string::const_iterator it = wordsB.begin();
20
21
while
(it != wordsB.end())
22
{
23
// skip over whitespace
24
while
(*it ==
' '
|| *it ==
'\n'
|| *it ==
'\t'
|| *it ==
'\r'
) {
25
if
(++it == wordsB.end())
break
;
26
}
27
28
std::string::const_iterator i1 = it;
29
30
// find first non-whitespace
31
while
(it != wordsB.end() &&
32
*it !=
' '
&& *it !=
'\n'
&& *it !=
'\t'
&& *it !=
'\r'
)
33
++it;
34
35
std::string w(i1, it);
36
37
if
(!
contains_word
(words, w)) {
38
if
(!words.empty())
39
words +=
' '
;
40
words += w;
41
}
42
}
43
44
return
words;
45
}
46
47
}
// namespace tlx
48
49
/******************************************************************************/
contains_word.hpp
tlx::union_words
std::string union_words(const std::string &wordsA, const std::string &wordsB)
Return union of two keyword sets.
Definition:
union_words.cpp:24
tlx
Definition:
exclusive_scan.hpp:17
union_words.hpp
tlx::contains_word
bool contains_word(const std::string &str, const char *word)
Search the given string for a whitespace-delimited word.
Definition:
contains_word.cpp:27
tlx
string
union_words.cpp
Generated on Wed Jul 29 2020 00:00:00 for tlx by
1.8.18