From 8e8ce973c672ba9dd39f593e600f41df32c269d3 Mon Sep 17 00:00:00 2001 From: Donatien Garnier Date: Fri, 24 Aug 2018 17:59:30 +0100 Subject: [PATCH] Run astyle --- features/nfc/nfc/NFCNDEFCapable.h | 2 +- features/nfc/nfc/NFCRemoteInitiator.h | 2 +- features/nfc/nfc/ndef/MessageBuilder.h | 18 +++++----- features/nfc/nfc/ndef/MessageParser.h | 2 +- features/nfc/nfc/ndef/Record.h | 4 +-- features/nfc/nfc/ndef/RecordParser.h | 2 +- features/nfc/nfc/ndef/common/Mime.h | 2 +- .../nfc/nfc/ndef/common/SimpleMessageParser.h | 3 +- features/nfc/nfc/ndef/common/Text.h | 2 +- features/nfc/nfc/ndef/common/URI.h | 2 +- features/nfc/nfc/ndef/common/util.h | 4 +-- features/nfc/source/nfc/NFCNDEFCapable.cpp | 2 +- .../nfc/source/nfc/ndef/MessageBuilder.cpp | 17 +++++----- .../nfc/source/nfc/ndef/MessageParser.cpp | 17 +++++----- features/nfc/source/nfc/ndef/common/Mime.cpp | 25 +++++++------- .../nfc/ndef/common/SimpleMessageParser.cpp | 9 +++-- features/nfc/source/nfc/ndef/common/Text.cpp | 33 +++++++++++-------- features/nfc/source/nfc/ndef/common/URI.cpp | 18 +++++----- features/nfc/source/nfc/ndef/common/util.cpp | 2 +- 19 files changed, 90 insertions(+), 76 deletions(-) diff --git a/features/nfc/nfc/NFCNDEFCapable.h b/features/nfc/nfc/NFCNDEFCapable.h index 57f5b23a4c..a5df6d061b 100644 --- a/features/nfc/nfc/NFCNDEFCapable.h +++ b/features/nfc/nfc/NFCNDEFCapable.h @@ -45,7 +45,7 @@ public: * Construct a NFCNDEFCapable instance. * @param[in] buffer a bytes array used to store NDEF messages */ - NFCNDEFCapable(const Span& buffer); + NFCNDEFCapable(const Span &buffer); /** * Check if this instance actually supports NDEF content. diff --git a/features/nfc/nfc/NFCRemoteInitiator.h b/features/nfc/nfc/NFCRemoteInitiator.h index 481256cc4b..aea21f57e6 100644 --- a/features/nfc/nfc/NFCRemoteInitiator.h +++ b/features/nfc/nfc/NFCRemoteInitiator.h @@ -49,7 +49,7 @@ public: * @param[in] buffer a bytes array used to store NDEF messages * @param[in] buffer_size the array size in bytes */ - NFCRemoteInitiator(NFCController *controller, const Span& buffer); + NFCRemoteInitiator(NFCController *controller, const Span &buffer); virtual ~NFCRemoteInitiator(); /** diff --git a/features/nfc/nfc/ndef/MessageBuilder.h b/features/nfc/nfc/ndef/MessageBuilder.h index 36db3fc8fa..27b130a838 100644 --- a/features/nfc/nfc/ndef/MessageBuilder.h +++ b/features/nfc/nfc/ndef/MessageBuilder.h @@ -62,9 +62,9 @@ public: * record inserted fit. */ bool append_record( - const RecordType &type, - const RecordPayload &payload = RecordPayload(), - bool is_last_record = false + const RecordType &type, + const RecordPayload &payload = RecordPayload(), + bool is_last_record = false ); /** @@ -109,17 +109,17 @@ private: // append fields void append_header(const Record &record); void append_type_length(const Record &record); - void append_payload_length(const Record&); - void append_id_length(const Record&); - void append_type(const Record&); - void append_id(const Record&); - void append_payload(const Record&); + void append_payload_length(const Record &); + void append_id_length(const Record &); + void append_type(const Record &); + void append_id(const Record &); + void append_payload(const Record &); // helpers static size_t compute_record_size(const Record &record); static bool is_short_payload(const Record &record); - // builder state. + // builder state. Span _message_buffer; size_t _position; bool _message_started; diff --git a/features/nfc/nfc/ndef/MessageParser.h b/features/nfc/nfc/ndef/MessageParser.h index f08aa77913..41a22bff4f 100644 --- a/features/nfc/nfc/ndef/MessageParser.h +++ b/features/nfc/nfc/ndef/MessageParser.h @@ -161,7 +161,7 @@ private: void report_parsing_started(); void report_record_parsed(const Record &record); void report_parsing_terminated(); - void report_parsing_error(error_t error, parsing_state_t& parsing_state); + void report_parsing_error(error_t error, parsing_state_t &parsing_state); Delegate *_delegate; }; diff --git a/features/nfc/nfc/ndef/Record.h b/features/nfc/nfc/ndef/Record.h index 7c5d2d690f..80afd69a44 100644 --- a/features/nfc/nfc/ndef/Record.h +++ b/features/nfc/nfc/ndef/Record.h @@ -193,12 +193,12 @@ struct Record { /** * If true, this record is a chunked record. */ - bool chunk:1; + bool chunk: 1; /** * If true, this record is the last one of the payload containing it. */ - bool last_record:1; + bool last_record: 1; }; diff --git a/features/nfc/nfc/ndef/RecordParser.h b/features/nfc/nfc/ndef/RecordParser.h index 8284453cc4..65ccb3d2fa 100644 --- a/features/nfc/nfc/ndef/RecordParser.h +++ b/features/nfc/nfc/ndef/RecordParser.h @@ -97,7 +97,7 @@ struct GenericRecordParser : public RecordParser { virtual bool parse(const Record &record) { ParsingResult parsed_value; - if (static_cast(this)->do_parse(record, parsed_value)) { + if (static_cast(this)->do_parse(record, parsed_value)) { if (_delegate) { _delegate->on_record_parsed(parsed_value, record.id); } diff --git a/features/nfc/nfc/ndef/common/Mime.h b/features/nfc/nfc/ndef/common/Mime.h index 1a88e5f16f..d84ef858bb 100644 --- a/features/nfc/nfc/ndef/common/Mime.h +++ b/features/nfc/nfc/ndef/common/Mime.h @@ -74,7 +74,7 @@ public: * @param to_copy The Mime object to copy. * @return a reference to this object */ - Mime& operator=(const Mime &other); + Mime &operator=(const Mime &other); /** * Set all attributes of a mime object. diff --git a/features/nfc/nfc/ndef/common/SimpleMessageParser.h b/features/nfc/nfc/ndef/common/SimpleMessageParser.h index 78970966ae..e9fea51a52 100644 --- a/features/nfc/nfc/ndef/common/SimpleMessageParser.h +++ b/features/nfc/nfc/ndef/common/SimpleMessageParser.h @@ -44,8 +44,7 @@ class SimpleMessageParser : MessageParser::Delegate, URIParser::Delegate, TextParser::Delegate, - MimeParser::Delegate -{ + MimeParser::Delegate { public: /** * Delegate invoked when the parser raise an event. diff --git a/features/nfc/nfc/ndef/common/Text.h b/features/nfc/nfc/ndef/common/Text.h index 76f72945b3..14853fc52a 100644 --- a/features/nfc/nfc/ndef/common/Text.h +++ b/features/nfc/nfc/ndef/common/Text.h @@ -84,7 +84,7 @@ public: * @param to_copy The Text instance to copy * @return a reference to this object. */ - Text& operator=(const Text &to_copy); + Text &operator=(const Text &to_copy); /** * Copy a text from an external buffer. diff --git a/features/nfc/nfc/ndef/common/URI.h b/features/nfc/nfc/ndef/common/URI.h index afef7d5285..3f4e5d3f78 100644 --- a/features/nfc/nfc/ndef/common/URI.h +++ b/features/nfc/nfc/ndef/common/URI.h @@ -115,7 +115,7 @@ public: * @param to_copy The URI to copy. * @return a reference to this object */ - URI& operator=(const URI &to_copy); + URI &operator=(const URI &to_copy); /** * Replace the value of the URI. diff --git a/features/nfc/nfc/ndef/common/util.h b/features/nfc/nfc/ndef/common/util.h index 40e38a301a..1be5577504 100644 --- a/features/nfc/nfc/ndef/common/util.h +++ b/features/nfc/nfc/ndef/common/util.h @@ -40,9 +40,9 @@ namespace common { * character. */ template -Span span_from_cstr(const char (&cstr)[N]) +Span < const uint8_t, N - 1 > span_from_cstr(const char (&cstr)[N]) { - return Span((const uint8_t*)cstr, N-1); + return Span < const uint8_t, N - 1 > ((const uint8_t *)cstr, N - 1); } /** diff --git a/features/nfc/source/nfc/NFCNDEFCapable.cpp b/features/nfc/source/nfc/NFCNDEFCapable.cpp index 2d9e78f30f..f4034f775e 100644 --- a/features/nfc/source/nfc/NFCNDEFCapable.cpp +++ b/features/nfc/source/nfc/NFCNDEFCapable.cpp @@ -25,7 +25,7 @@ using namespace mbed; using namespace mbed::nfc; -NFCNDEFCapable::NFCNDEFCapable(const Span& buffer) : _delegate(NULL) +NFCNDEFCapable::NFCNDEFCapable(const Span &buffer) : _delegate(NULL) { ndef_msg_init(&_ndef_message, s_ndef_encode, s_ndef_decode, buffer.data(), buffer.size(), this); } diff --git a/features/nfc/source/nfc/ndef/MessageBuilder.cpp b/features/nfc/source/nfc/ndef/MessageBuilder.cpp index a71c840a53..ca824acbb0 100644 --- a/features/nfc/source/nfc/ndef/MessageBuilder.cpp +++ b/features/nfc/source/nfc/ndef/MessageBuilder.cpp @@ -31,10 +31,11 @@ MessageBuilder::MessageBuilder(const Span &buffer) : { } bool MessageBuilder::append_record( - const RecordType &type, - const RecordPayload &payload, - bool is_last_record -) { + const RecordType &type, + const RecordPayload &payload, + bool is_last_record +) +{ Record record( type, payload, @@ -93,10 +94,10 @@ bool MessageBuilder::append_record(const Record &record) } if (record.type.tnf == RecordType::well_known_type || - record.type.tnf == RecordType::media_type || - record.type.tnf == RecordType::absolute_uri || - record.type.tnf == RecordType::external_type - ) { + record.type.tnf == RecordType::media_type || + record.type.tnf == RecordType::absolute_uri || + record.type.tnf == RecordType::external_type + ) { if (record.type.value.empty()) { return false; } diff --git a/features/nfc/source/nfc/ndef/MessageParser.cpp b/features/nfc/source/nfc/ndef/MessageParser.cpp index da06f8c6a5..c0df603f90 100644 --- a/features/nfc/source/nfc/ndef/MessageParser.cpp +++ b/features/nfc/source/nfc/ndef/MessageParser.cpp @@ -102,9 +102,9 @@ struct MessageParser::parsing_state_t { { } buffer_iterator_t it; - bool first_record_parsed:1; - bool last_record_parsed:1; - bool error:1; + bool first_record_parsed: 1; + bool last_record_parsed: 1; + bool error: 1; }; MessageParser::MessageParser() : @@ -120,7 +120,7 @@ void MessageParser::parse(const Span &data_buffer) { parsing_state_t parsing_state(data_buffer); report_parsing_started(); - while(parsing_state.it && parse_record(parsing_state)); + while (parsing_state.it && parse_record(parsing_state)); if (!parsing_state.error && !parsing_state.last_record_parsed) { report_parsing_error(MISSING_MESSAGE_END, parsing_state); } @@ -251,8 +251,8 @@ bool MessageParser::parse_record(parsing_state_t &s) uint8_t MessageParser::compute_lengths_size(uint8_t header) { return 1 /* type_length size */ + - ((header & Header::short_record_bit) ? 1 : 4) /* payload length */ + - ((header & Header::id_length_bit) ? 1 : 0); + ((header & Header::short_record_bit) ? 1 : 4) /* payload length */ + + ((header & Header::id_length_bit) ? 1 : 0); } uint8_t MessageParser::extract_type_length(parsing_state_t &s) @@ -267,7 +267,7 @@ uint32_t MessageParser::extract_payload_length(parsing_state_t &s, uint8_t heade payload_length = *s.it++; } else { s.it.read_be( - reinterpret_cast(&payload_length), + reinterpret_cast(&payload_length), sizeof(payload_length) ); } @@ -279,7 +279,8 @@ uint8_t MessageParser::extract_id_length(parsing_state_t &s, uint8_t header) return (header & Header::id_length_bit) ? *s.it++ : 0; } -void MessageParser::report_parsing_started() { +void MessageParser::report_parsing_started() +{ if (_delegate) { _delegate->on_parsing_started(); } diff --git a/features/nfc/source/nfc/ndef/common/Mime.cpp b/features/nfc/source/nfc/ndef/common/Mime.cpp index 496e31e8d3..77074a8234 100644 --- a/features/nfc/source/nfc/ndef/common/Mime.cpp +++ b/features/nfc/source/nfc/ndef/common/Mime.cpp @@ -53,7 +53,7 @@ Mime::~Mime() delete[] _mime; } -Mime& Mime::operator=(const Mime &to_copy) +Mime &Mime::operator=(const Mime &to_copy) { if (this == &to_copy) { return * this; @@ -72,7 +72,8 @@ Mime& Mime::operator=(const Mime &to_copy) void Mime::set_mime( const Span &mime_type, const Span &content -) { +) +{ delete[] _mime; _mime = new uint8_t[mime_type.size() + content.size()]; @@ -95,22 +96,24 @@ Span Mime::get_mime_content() const bool Mime::append_as_record( MessageBuilder &message_builder, bool is_last_record -) { +) +{ return message_builder.append_record( - RecordType( - RecordType::media_type, - get_mime_type() - ), - get_mime_content(), - is_last_record - ); + RecordType( + RecordType::media_type, + get_mime_type() + ), + get_mime_content(), + is_last_record + ); } void Mime::move_data( uint8_t *mime_record, size_t mime_type_size, size_t mime_content_size -) { +) +{ delete[] _mime; _mime = mime_record; _type_size = mime_type_size; diff --git a/features/nfc/source/nfc/ndef/common/SimpleMessageParser.cpp b/features/nfc/source/nfc/ndef/common/SimpleMessageParser.cpp index fcf872f7ca..5f0db5a0f1 100644 --- a/features/nfc/source/nfc/ndef/common/SimpleMessageParser.cpp +++ b/features/nfc/source/nfc/ndef/common/SimpleMessageParser.cpp @@ -89,7 +89,8 @@ void SimpleMessageParser::on_parsing_terminated() void SimpleMessageParser::on_record_parsed( const URI &uri, const RecordID &id -) { +) +{ if (_delegate) { _delegate->on_uri_parsed(uri, id); } @@ -98,7 +99,8 @@ void SimpleMessageParser::on_record_parsed( void SimpleMessageParser::on_record_parsed( const Text &text, const RecordID &id -) { +) +{ if (_delegate) { _delegate->on_text_parsed(text, id); } @@ -107,7 +109,8 @@ void SimpleMessageParser::on_record_parsed( void SimpleMessageParser::on_record_parsed( const Mime &mime, const RecordID &id -) { +) +{ if (_delegate) { _delegate->on_mime_parsed(mime, id); } diff --git a/features/nfc/source/nfc/ndef/common/Text.cpp b/features/nfc/source/nfc/ndef/common/Text.cpp index ea7979e8fa..478bdd89d9 100644 --- a/features/nfc/source/nfc/ndef/common/Text.cpp +++ b/features/nfc/source/nfc/ndef/common/Text.cpp @@ -59,7 +59,7 @@ Text::~Text() delete[] _text_record; } -Text& Text::operator=(const Text &other) +Text &Text::operator=(const Text &other) { if (this == &other) { return *this; @@ -82,7 +82,8 @@ void Text::set_text( encoding_t text_encoding, const Span &language_code, const Span &text -) { +) +{ delete[] _text_record; _text_record_size = header_size + language_code.size() + text.size(); @@ -107,23 +108,26 @@ Text::encoding_t Text::get_encoding() const return (_text_record[header_index] & utf16_encoding_bit) ? UTF16 : UTF8; } -Span Text::get_language_code() const { +Span Text::get_language_code() const +{ return make_const_Span( - _text_record + language_code_index, - _text_record[header_index] & language_code_size_mask - ); + _text_record + language_code_index, + _text_record[header_index] & language_code_size_mask + ); } -Span Text::get_text() const { +Span Text::get_text() const +{ size_t language_code_size = get_language_code().size(); return make_const_Span( - _text_record + header_size + language_code_size, - _text_record_size - header_size - language_code_size - ); + _text_record + header_size + language_code_size, + _text_record_size - header_size - language_code_size + ); } -void Text::move_data(uint8_t *text, size_t size) { +void Text::move_data(uint8_t *text, size_t size) +{ delete[] _text_record; _text_record = text; _text_record_size = size; @@ -132,7 +136,8 @@ void Text::move_data(uint8_t *text, size_t size) { bool Text::append_as_record( MessageBuilder &message_builder, bool is_last_record -) { +) +{ // Build the record type RecordType type( RecordType::well_known_type, @@ -152,8 +157,8 @@ bool TextParser::do_parse(const Record &record, Text &text) // the record type value should be equal to `T` if (record.type.value != make_const_Span(text_record_type_value) || - record.payload.empty() - ) { + record.payload.empty() + ) { return false; } diff --git a/features/nfc/source/nfc/ndef/common/URI.cpp b/features/nfc/source/nfc/ndef/common/URI.cpp index 7213bac929..f1ecf984e7 100644 --- a/features/nfc/source/nfc/ndef/common/URI.cpp +++ b/features/nfc/source/nfc/ndef/common/URI.cpp @@ -32,7 +32,8 @@ namespace common { URI::URI() : _uri(NULL), - _uri_size(0) { + _uri_size(0) +{ } URI::URI(uri_identifier_code_t id, const Span &uri_field) : @@ -55,7 +56,7 @@ URI::~URI() delete[] _uri; } -URI& URI::operator=(const URI &other) +URI &URI::operator=(const URI &other) { delete[] _uri; @@ -74,7 +75,8 @@ URI& URI::operator=(const URI &other) void URI::set_uri( uri_identifier_code_t id, const Span &uri_field -) { +) +{ delete[] _uri; if (uri_field.empty()) { @@ -104,9 +106,9 @@ Span URI::get_uri_field() const return Span(); } return make_const_Span( - _uri + uri_field_index, - _uri_size - uri_id_code_size - ); + _uri + uri_field_index, + _uri_size - uri_id_code_size + ); } bool URI::append_as_record(MessageBuilder &message_builder, bool is_last_record) @@ -142,8 +144,8 @@ bool URIParser::do_parse(const Record &record, URI &uri) // the record type value should be equal to `U` if (record.type.value != make_const_Span(uri_record_type_value) || - record.payload.empty() - ) { + record.payload.empty() + ) { return false; } diff --git a/features/nfc/source/nfc/ndef/common/util.cpp b/features/nfc/source/nfc/ndef/common/util.cpp index ed4e3ff417..4ffed52852 100644 --- a/features/nfc/source/nfc/ndef/common/util.cpp +++ b/features/nfc/source/nfc/ndef/common/util.cpp @@ -25,7 +25,7 @@ namespace common { Span span_from_cstr(const char *cstr) { - return Span((const uint8_t*)cstr, strlen(cstr)); + return Span((const uint8_t *)cstr, strlen(cstr)); } /**