Welcome to mirror list, hosted at ThFree Co, Russian Federation.

house_numbers_matcher.hpp « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a32cfc72006ee1a4819f3249eac954dac827c13e (plain)
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
74
75
76
77
78
79
#pragma once

#include "base/string_utils.hpp"

#include <string>
#include <utility>
#include <vector>

namespace search
{
namespace house_numbers
{
struct Token
{
  enum Type
  {
    TYPE_NUMBER,
    TYPE_SEPARATOR,
    TYPE_GROUP_SEPARATOR,
    TYPE_HYPHEN,
    TYPE_SLASH,
    TYPE_STRING,
    TYPE_BUILDING_PART,
    TYPE_LETTER,
    TYPE_BUILDING_PART_OR_LETTER
  };

  Token() = default;
  Token(strings::UniString const & value, Type type) : m_value(value), m_type(type) {}
  Token(strings::UniString && value, Type type) : m_value(std::move(value)), m_type(type) {}
  Token(Token &&) = default;

  Token & operator=(Token &&) = default;
  Token & operator=(Token const &) = default;

  bool operator==(Token const & rhs) const
  {
    return m_type == rhs.m_type && m_value == rhs.m_value;
  }

  bool operator!=(Token const & rhs) const { return !(*this == rhs); }

  bool operator<(Token const & rhs) const
  {
    if (m_type != rhs.m_type)
      return m_type < rhs.m_type;
    return m_value < rhs.m_value;
  }

  strings::UniString m_value;
  Type m_type = TYPE_SEPARATOR;
  bool m_prefix = false;
};

// Tokenizes |s| that may be a house number.
void Tokenize(strings::UniString s, bool isPrefix, std::vector<Token> & ts);

// Parses a string that can be one or more house numbers. This method
// can be used to parse addr:housenumber fields.
void ParseHouseNumber(strings::UniString const & s, std::vector<std::vector<Token>> & parses);

// Parses a part of search query that can be a house number.
void ParseQuery(strings::UniString const & query, bool queryIsPrefix, std::vector<Token> & parse);

// Returns true if house number matches to a given query.
bool HouseNumbersMatch(strings::UniString const & houseNumber, strings::UniString const & query,
                       bool queryIsPrefix);

// Returns true if house number matches to a given parsed query.
bool HouseNumbersMatch(strings::UniString const & houseNumber, std::vector<Token> const & queryParse);

// Returns true if |s| looks like a house number.
bool LooksLikeHouseNumber(strings::UniString const & s, bool isPrefix);

std::string DebugPrint(Token::Type type);

std::string DebugPrint(Token const & token);
}  // namespace house_numbers
}  // namespace search