File: vector.hpp

package info (click to toggle)
ares 126-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,600 kB
  • sloc: cpp: 356,508; ansic: 20,394; makefile: 16; sh: 2
file content (60 lines) | stat: -rw-r--r-- 1,434 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once

namespace nall {

template<typename... P> inline auto vector<string>::append(const string& data, P&&... p) -> type& {
  vector_base::append(data);
  append(forward<P>(p)...);
  return *this;
}

inline auto vector<string>::append() -> type& {
  return *this;
}

inline auto vector<string>::isort() -> type& {
  sort([](const string& x, const string& y) {
    return memory::icompare(x.data(), x.size(), y.data(), y.size()) < 0;
  });
  return *this;
}

inline auto vector<string>::find(string_view source) const -> maybe<u32> {
  for(u32 n = 0; n < size(); n++) {
    if(operator[](n).equals(source)) return n;
  }
  return {};
}

inline auto vector<string>::ifind(string_view source) const -> maybe<u32> {
  for(u32 n = 0; n < size(); n++) {
    if(operator[](n).iequals(source)) return n;
  }
  return {};
}

inline auto vector<string>::match(string_view pattern) const -> vector<string> {
  vector<string> result;
  for(u32 n = 0; n < size(); n++) {
    if(operator[](n).match(pattern)) result.append(operator[](n));
  }
  return result;
}

inline auto vector<string>::merge(string_view separator) const -> string {
  string output;
  for(u32 n = 0; n < size(); n++) {
    output.append(operator[](n));
    if(n < size() - 1) output.append(separator.data());
  }
  return output;
}

inline auto vector<string>::strip() -> type& {
  for(u32 n = 0; n < size(); n++) {
    operator[](n).strip();
  }
  return *this;
}

}