Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
index_of.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/string/index_of.cpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2007-2017 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #include <tlx/string/index_of.hpp>
12 
14 
15 #include <stdexcept>
16 
17 namespace tlx {
18 
19 size_t index_of(const std::vector<std::string>& list, const char* str) {
20  for (size_t i = 0; i < list.size(); ++i) {
21  if (list[i] == str)
22  return i;
23  }
24  std::string reason = "Could not find index_of() ";
25  reason += str;
26  throw std::runtime_error(reason);
27 }
28 
29 size_t index_of(const std::vector<std::string>& list, const std::string& str) {
30  for (size_t i = 0; i < list.size(); ++i) {
31  if (list[i] == str)
32  return i;
33  }
34  std::string reason = "Could not find index_of() ";
35  reason += str;
36  throw std::runtime_error(reason);
37 }
38 
39 size_t index_of_icase(const std::vector<std::string>& list, const char* str) {
40  for (size_t i = 0; i < list.size(); ++i) {
41  if (tlx::equal_icase(list[i], str))
42  return i;
43  }
44  std::string reason = "Could not find index_of_icase() ";
45  reason += str;
46  throw std::runtime_error(reason);
47 }
48 
49 size_t
50 index_of_icase(const std::vector<std::string>& list, const std::string& str) {
51  for (size_t i = 0; i < list.size(); ++i) {
52  if (tlx::equal_icase(list[i], str))
53  return i;
54  }
55  std::string reason = "Could not find index_of_icase() ";
56  reason += str;
57  throw std::runtime_error(reason);
58 }
59 
60 } // namespace tlx
61 
62 /******************************************************************************/
bool equal_icase(const char *a, const char *b)
returns true if a == b without regard for letter case
Definition: equal_icase.cpp:18
size_t index_of_icase(const std::vector< std::string > &list, const char *str)
Attempts to find str in the list and return the index using case-insensitive comparisons.
Definition: index_of.cpp:39
size_t index_of(const std::vector< std::string > &list, const char *str)
Attempts to find str in the list and return the index.
Definition: index_of.cpp:19
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220