File: list.hpp

package info (click to toggle)
higan 106-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 9,640 kB
  • sloc: cpp: 108,736; ansic: 809; makefile: 22; sh: 7
file content (73 lines) | stat: -rw-r--r-- 1,743 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
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once

namespace nall {

auto string_vector::operator==(const string_vector& source) const -> bool {
  if(this == &source) return true;
  if(size() != source.size()) return false;
  for(uint n = 0; n < size(); n++) {
    if(operator[](n) != source[n]) return false;
  }
  return true;
}

auto string_vector::operator!=(const string_vector& source) const -> bool {
  return !operator==(source);
}

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

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

auto string_vector::append() -> type& {
  return *this;
}

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

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

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

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

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

}