Mistake on this page?
Report an issue in GitHub or email us
Text.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2018 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef NFC_COMMON_TEXT_H_
18 #define NFC_COMMON_TEXT_H_
19 
20 #include <stdint.h>
21 
22 #include "platform/Span.h"
23 
24 #include "nfc/ndef/RecordParser.h"
25 #include "nfc/ndef/MessageBuilder.h"
26 
27 namespace mbed {
28 namespace nfc {
29 namespace ndef {
30 namespace common {
31 
32 /**
33  * @addtogroup nfc
34  * @{
35  */
36 
37 /**
38  * Represent the well known type text.
39  */
40 class Text {
41 public:
42  /**
43  * Encoding of the text.
44  */
45  enum encoding_t {
46  UTF8 = 0,//!< UTF8
47  UTF16 = 1//!< UTF16
48  };
49 
50  /**
51  * Construct an empty text element.
52  */
53  Text();
54 
55  /**
56  * Construct a text element from a data buffer and an encoding.
57  *
58  * @param text_encoding The encoding of the text.
59  * @param language_code The string of the language code.
60  * @param text The text buffer.
61  *
62  * @note To remove the NULL terminator of the C-string of the language_code
63  * and text parameters, you can use the utility function span_from_cstr.
64  */
65  Text(
66  encoding_t text_encoding,
67  const Span<const uint8_t> &language_code,
68  const Span<const uint8_t> &text
69  );
70 
71  /**
72  * Copy construct a text element.
73  * @param to_copy
74  */
75  Text(const Text &to_copy);
76 
77  /**
78  * Destroy a text element.
79  */
80  ~Text();
81 
82  /**
83  * Copy assignment of another text element.
84  * @param to_copy The Text instance to copy
85  * @return a reference to this object.
86  */
87  Text &operator=(const Text &to_copy);
88 
89  /**
90  * Copy a text from an external buffer.
91  *
92  * @param text_encoding The encoding of the text.
93  * @param language_code The language code of the text.
94  * @param text The text to copy.
95  *
96  * @note To remove the NULL terminator of the C-string of the language_code
97  * and text parameters, you can use the utility function span_from_cstr.
98  */
99  void set_text(
100  encoding_t text_encoding,
101  const Span<const uint8_t> &language_code,
102  const Span<const uint8_t> &text
103  );
104 
105  /**
106  * Get the encoding of the text.
107  * @return The encoding of the text.
108  */
109  encoding_t get_encoding() const;
110 
111  /**
112  * Return the language code.
113  * @return The language code.
114  */
116 
117  /**
118  * Return the text contained in this object.
119  * @return The text contained in this object.
120  */
122 
123  /**
124  * Append into a message builder
125  */
126  bool append_as_record(
127  MessageBuilder &message_builder,
128  bool is_last_record = false
129  ) const;
130 
131  /**
132  * Compute the size of this object in a ndef record.
133  *
134  * @return The size of the ndef record required to store this object.
135  */
136  size_t get_record_size() const;
137 
138 private:
139  friend class TextParser;
140 
141  void move_data(uint8_t *text, size_t size);
142 
143  uint8_t *_text_record;
144  size_t _text_record_size;
145 };
146 
147 /**
148  * Parse a Text.
149  */
150 class TextParser : public GenericRecordParser<TextParser, Text> {
151 public:
152  virtual bool do_parse(const Record &record, Text &text);
153 };
154 
155 /**
156  * @}
157  */
158 
159 } // namespace common
160 } // namespace ndef
161 } // namespace nfc
162 } // namespace mbed
163 
164 
165 #endif /* NFC_COMMON_TEXT_H_ */
Construct a NDEF Message.
encoding_t get_encoding() const
Get the encoding of the text.
~Text()
Destroy a text element.
bool append_as_record(MessageBuilder &message_builder, bool is_last_record=false) const
Append into a message builder.
size_t get_record_size() const
Compute the size of this object in a ndef record.
Span< const uint8_t > get_language_code() const
Return the language code.
void set_text(encoding_t text_encoding, const Span< const uint8_t > &language_code, const Span< const uint8_t > &text)
Copy a text from an external buffer.
Represent the well known type text.
Definition: Text.h:40
Represent a record.
Definition: Record.h:148
Span< const uint8_t > get_text() const
Return the text contained in this object.
Text()
Construct an empty text element.
Text & operator=(const Text &to_copy)
Copy assignment of another text element.
encoding_t
Encoding of the text.
Definition: Text.h:45
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.