[47/51] [abbrv] [partial] nifi-minifi-cpp git commit: MINIFI-68 Adding yaml-cpp source and updating LICENSE to reflect its inclusion.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/4dd46e29/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/emitterutils.h -- diff --git a/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/emitterutils.h b/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/emitterutils.h new file mode 100644 index 000..3a9c2f8 --- /dev/null +++ b/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/emitterutils.h @@ -0,0 +1,50 @@ +#ifndef EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) ||\ +(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include + +#include "emitterstate.h" +#include "yaml-cpp/emittermanip.h" +#include "yaml-cpp/ostream_wrapper.h" + +namespace YAML { +class ostream_wrapper; +} // namespace YAML + +namespace YAML { +class Binary; + +struct StringFormat { + enum value { Plain, SingleQuoted, DoubleQuoted, Literal }; +}; + +namespace Utils { +StringFormat::value ComputeStringFormat(const std::string& str, +EMITTER_MANIP strFormat, +FlowType::value flowType, +bool escapeNonAscii); + +bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str); +bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str, + bool escapeNonAscii); +bool WriteLiteralString(ostream_wrapper& out, const std::string& str, +int indent); +bool WriteChar(ostream_wrapper& out, char ch); +bool WriteComment(ostream_wrapper& out, const std::string& str, + int postCommentIndent); +bool WriteAlias(ostream_wrapper& out, const std::string& str); +bool WriteAnchor(ostream_wrapper& out, const std::string& str); +bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim); +bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix, +const std::string& tag); +bool WriteBinary(ostream_wrapper& out, const Binary& binary); +} +} + +#endif // EMITTERUTILS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/4dd46e29/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/exp.cpp -- diff --git a/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/exp.cpp b/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/exp.cpp new file mode 100644 index 000..695440a --- /dev/null +++ b/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/exp.cpp @@ -0,0 +1,136 @@ +#include + +#include "exp.h" +#include "stream.h" +#include "yaml-cpp/exceptions.h" // IWYU pragma: keep + +namespace YAML { +struct Mark; +} // namespace YAML + +namespace YAML { +namespace Exp { +unsigned ParseHex(const std::string& str, const Mark& mark) { + unsigned value = 0; + for (std::size_t i = 0; i < str.size(); i++) { +char ch = str[i]; +int digit = 0; +if ('a' <= ch && ch <= 'f') + digit = ch - 'a' + 10; +else if ('A' <= ch && ch <= 'F') + digit = ch - 'A' + 10; +else if ('0' <= ch && ch <= '9') + digit = ch - '0'; +else + throw ParserException(mark, ErrorMsg::INVALID_HEX); + +value = (value << 4) + digit; + } + + return value; +} + +std::string Str(unsigned ch) { return std::string(1, static_cast(ch)); } + +// Escape +// . Translates the next 'codeLength' characters into a hex number and returns +// the result. +// . Throws if it's not actually hex. +std::string Escape(Stream& in, int codeLength) { + // grab string + std::string str; + for (int i = 0; i < codeLength; i++) +str += in.get(); + + // get the value + unsigned value = ParseHex(str, in.mark()); + + // legal unicode? + if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10) { +std::stringstream msg; +msg << ErrorMsg::INVALID_UNICODE << value; +throw ParserException(in.mark(), msg.str()); + } + + // now break it up into chars + if (value <= 0x7F) +return Str(value); + else if (value <= 0x7FF) +return Str(0xC0 + (value >> 6)) + Str(0x80 + (value & 0x3F)); + else if (value <= 0x) +return Str(0xE0 + (value >> 12)) + Str(0x80 + ((value >> 6) & 0x3F)) + + Str(0x80 + (value & 0x3F)); + else +return Str(0xF0 + (value >> 18)) + Str(0x80 + ((value >> 12) & 0x3F)) + + Str(0x80 + ((value >> 6) & 0x3F)) + Str(0x80 + (value & 0x3F)); +} + +// Escape +// . Escapes the sequence starting 'in' (it must begin with a '\' or single +// quote) +// and returns the result. +// . Throws if it's an unknown escape character. +std::string Escape(Stream& in) { + // eat slash + char escape = in.get(); + + // switch on escape character + char ch = in.get(); + + // first do single quote, since it's easier + if
[47/51] [abbrv] [partial] nifi-minifi-cpp git commit: MINIFI-68 Adding yaml-cpp source and updating LICENSE to reflect its inclusion.
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/cf813d4d/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/emitterutils.cpp -- diff --git a/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/emitterutils.cpp b/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/emitterutils.cpp new file mode 100644 index 000..4a4c982 --- /dev/null +++ b/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/emitterutils.cpp @@ -0,0 +1,484 @@ +#include +#include + +#include "emitterutils.h" +#include "exp.h" +#include "indentation.h" +#include "regex_yaml.h" +#include "regeximpl.h" +#include "stringsource.h" +#include "yaml-cpp/binary.h" // IWYU pragma: keep +#include "yaml-cpp/ostream_wrapper.h" + +namespace YAML { +namespace Utils { +namespace { +enum { REPLACEMENT_CHARACTER = 0xFFFD }; + +bool IsAnchorChar(int ch) { // test for ns-anchor-char + switch (ch) { +case ',': +case '[': +case ']': +case '{': +case '}': // c-flow-indicator +case ' ': +case '\t':// s-white +case 0xFEFF: // c-byte-order-mark +case 0xA: +case 0xD: // b-char + return false; +case 0x85: + return true; + } + + if (ch < 0x20) { +return false; + } + + if (ch < 0x7E) { +return true; + } + + if (ch < 0xA0) { +return false; + } + if (ch >= 0xD800 && ch <= 0xDFFF) { +return false; + } + if ((ch & 0xFFFE) == 0xFFFE) { +return false; + } + if ((ch >= 0xFDD0) && (ch <= 0xFDEF)) { +return false; + } + if (ch > 0x10) { +return false; + } + + return true; +} + +int Utf8BytesIndicated(char ch) { + int byteVal = static_cast(ch); + switch (byteVal >> 4) { +case 0: +case 1: +case 2: +case 3: +case 4: +case 5: +case 6: +case 7: + return 1; +case 12: +case 13: + return 2; +case 14: + return 3; +case 15: + return 4; +default: + return -1; + } +} + +bool IsTrailingByte(char ch) { return (ch & 0xC0) == 0x80; } + +bool GetNextCodePointAndAdvance(int& codePoint, +std::string::const_iterator& first, +std::string::const_iterator last) { + if (first == last) +return false; + + int nBytes = Utf8BytesIndicated(*first); + if (nBytes < 1) { +// Bad lead byte +++first; +codePoint = REPLACEMENT_CHARACTER; +return true; + } + + if (nBytes == 1) { +codePoint = *first++; +return true; + } + + // Gather bits from trailing bytes + codePoint = static_cast(*first) & ~(0xFF << (7 - nBytes)); + ++first; + --nBytes; + for (; nBytes > 0; ++first, --nBytes) { +if ((first == last) || !IsTrailingByte(*first)) { + codePoint = REPLACEMENT_CHARACTER; + break; +} +codePoint <<= 6; +codePoint |= *first & 0x3F; + } + + // Check for illegal code points + if (codePoint > 0x10) +codePoint = REPLACEMENT_CHARACTER; + else if (codePoint >= 0xD800 && codePoint <= 0xDFFF) +codePoint = REPLACEMENT_CHARACTER; + else if ((codePoint & 0xFFFE) == 0xFFFE) +codePoint = REPLACEMENT_CHARACTER; + else if (codePoint >= 0xFDD0 && codePoint <= 0xFDEF) +codePoint = REPLACEMENT_CHARACTER; + return true; +} + +void WriteCodePoint(ostream_wrapper& out, int codePoint) { + if (codePoint < 0 || codePoint > 0x10) { +codePoint = REPLACEMENT_CHARACTER; + } + if (codePoint < 0x7F) { +out << static_cast(codePoint); + } else if (codePoint < 0x7FF) { +out << static_cast(0xC0 | (codePoint >> 6)) +<< static_cast(0x80 | (codePoint & 0x3F)); + } else if (codePoint < 0x) { +out << static_cast(0xE0 | (codePoint >> 12)) +<< static_cast(0x80 | ((codePoint >> 6) & 0x3F)) +<< static_cast(0x80 | (codePoint & 0x3F)); + } else { +out << static_cast(0xF0 | (codePoint >> 18)) +<< static_cast(0x80 | ((codePoint >> 12) & 0x3F)) +<< static_cast(0x80 | ((codePoint >> 6) & 0x3F)) +<< static_cast(0x80 | (codePoint & 0x3F)); + } +} + +bool IsValidPlainScalar(const std::string& str, FlowType::value flowType, +bool allowOnlyAscii) { + if (str.empty()) { +return false; + } + + // check against null + if (str == "null") { +return false; + } + + // check the start + const RegEx& start = (flowType == FlowType::Flow ? Exp::PlainScalarInFlow() + : Exp::PlainScalar()); + if (!start.Matches(str)) { +return false; + } + + // and check the end for plain whitespace (which can't be faithfully kept in a + // plain scalar) + if (!str.empty() && *str.rbegin() == ' ') { +return false; + } + + // then check until something is disallowed + static const RegEx& disallowed_flow = + Exp::EndScalarInFlow() || (Exp::BlankOrBreak() + Exp::Comment()) || + Exp::NotPrintable() || Exp::Utf8_ByteOrderMark() || Exp::Break() || + Exp::Tab(); + static const RegEx& disallowed_block = + Exp::EndScalar() ||