1// Copyright (C) 2014 Google Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "format_element.h"
16
17#include <libaddressinput/address_field.h>
18
19#include <cassert>
20#include <ostream>
21
22namespace i18n {
23namespace addressinput {
24
25FormatElement::FormatElement(AddressField field) : field_(field), literal_() {}
26
27FormatElement::FormatElement(const std::string& literal)
28    : field_(static_cast<AddressField>(-1)), literal_(literal) {
29  assert(!literal.empty());
30}
31
32FormatElement::FormatElement()
33    : field_(static_cast<AddressField>(-1)), literal_("\n") {}
34
35bool FormatElement::operator==(const FormatElement& other) const {
36  return field_ == other.field_ && literal_ == other.literal_;
37}
38
39}  // namespace addressinput
40}  // namespace i18n
41
42std::ostream& operator<<(std::ostream& o,
43                         const i18n::addressinput::FormatElement& element) {
44  if (element.IsField()) {
45    o << "Field: " << element.GetField();
46  } else if (element.IsNewline()) {
47    o << "Newline";
48  } else {
49    o << "Literal: " << element.GetLiteral();
50  }
51  return o;
52}
53