[46/51] [abbrv] [partial] nifi-minifi-cpp git commit: MINIFI-68 Adding yaml-cpp source and updating LICENSE to reflect its inclusion.

2016-08-02 Thread aldrin
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/4dd46e29/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/scantoken.cpp
--
diff --git a/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/scantoken.cpp 
b/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/scantoken.cpp
new file mode 100644
index 000..180ad00
--- /dev/null
+++ b/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/scantoken.cpp
@@ -0,0 +1,436 @@
+#include 
+
+#include "exp.h"
+#include "regex_yaml.h"
+#include "regeximpl.h"
+#include "scanner.h"
+#include "scanscalar.h"
+#include "scantag.h"  // IWYU pragma: keep
+#include "tag.h"  // IWYU pragma: keep
+#include "token.h"
+#include "yaml-cpp/exceptions.h"  // IWYU pragma: keep
+#include "yaml-cpp/mark.h"
+
+namespace YAML {
+///
+// Specialization for scanning specific tokens
+
+// Directive
+// . Note: no semantic checking is done here (that's for the parser to do)
+void Scanner::ScanDirective() {
+  std::string name;
+  std::vector params;
+
+  // pop indents and simple keys
+  PopAllIndents();
+  PopAllSimpleKeys();
+
+  m_simpleKeyAllowed = false;
+  m_canBeJSONFlow = false;
+
+  // store pos and eat indicator
+  Token token(Token::DIRECTIVE, INPUT.mark());
+  INPUT.eat(1);
+
+  // read name
+  while (INPUT && !Exp::BlankOrBreak().Matches(INPUT))
+token.value += INPUT.get();
+
+  // read parameters
+  while (1) {
+// first get rid of whitespace
+while (Exp::Blank().Matches(INPUT))
+  INPUT.eat(1);
+
+// break on newline or comment
+if (!INPUT || Exp::Break().Matches(INPUT) || Exp::Comment().Matches(INPUT))
+  break;
+
+// now read parameter
+std::string param;
+while (INPUT && !Exp::BlankOrBreak().Matches(INPUT))
+  param += INPUT.get();
+
+token.params.push_back(param);
+  }
+
+  m_tokens.push(token);
+}
+
+// DocStart
+void Scanner::ScanDocStart() {
+  PopAllIndents();
+  PopAllSimpleKeys();
+  m_simpleKeyAllowed = false;
+  m_canBeJSONFlow = false;
+
+  // eat
+  Mark mark = INPUT.mark();
+  INPUT.eat(3);
+  m_tokens.push(Token(Token::DOC_START, mark));
+}
+
+// DocEnd
+void Scanner::ScanDocEnd() {
+  PopAllIndents();
+  PopAllSimpleKeys();
+  m_simpleKeyAllowed = false;
+  m_canBeJSONFlow = false;
+
+  // eat
+  Mark mark = INPUT.mark();
+  INPUT.eat(3);
+  m_tokens.push(Token(Token::DOC_END, mark));
+}
+
+// FlowStart
+void Scanner::ScanFlowStart() {
+  // flows can be simple keys
+  InsertPotentialSimpleKey();
+  m_simpleKeyAllowed = true;
+  m_canBeJSONFlow = false;
+
+  // eat
+  Mark mark = INPUT.mark();
+  char ch = INPUT.get();
+  FLOW_MARKER flowType = (ch == Keys::FlowSeqStart ? FLOW_SEQ : FLOW_MAP);
+  m_flows.push(flowType);
+  Token::TYPE type =
+  (flowType == FLOW_SEQ ? Token::FLOW_SEQ_START : Token::FLOW_MAP_START);
+  m_tokens.push(Token(type, mark));
+}
+
+// FlowEnd
+void Scanner::ScanFlowEnd() {
+  if (InBlockContext())
+throw ParserException(INPUT.mark(), ErrorMsg::FLOW_END);
+
+  // we might have a solo entry in the flow context
+  if (InFlowContext()) {
+if (m_flows.top() == FLOW_MAP && VerifySimpleKey())
+  m_tokens.push(Token(Token::VALUE, INPUT.mark()));
+else if (m_flows.top() == FLOW_SEQ)
+  InvalidateSimpleKey();
+  }
+
+  m_simpleKeyAllowed = false;
+  m_canBeJSONFlow = true;
+
+  // eat
+  Mark mark = INPUT.mark();
+  char ch = INPUT.get();
+
+  // check that it matches the start
+  FLOW_MARKER flowType = (ch == Keys::FlowSeqEnd ? FLOW_SEQ : FLOW_MAP);
+  if (m_flows.top() != flowType)
+throw ParserException(mark, ErrorMsg::FLOW_END);
+  m_flows.pop();
+
+  Token::TYPE type = (flowType ? Token::FLOW_SEQ_END : Token::FLOW_MAP_END);
+  m_tokens.push(Token(type, mark));
+}
+
+// FlowEntry
+void Scanner::ScanFlowEntry() {
+  // we might have a solo entry in the flow context
+  if (InFlowContext()) {
+if (m_flows.top() == FLOW_MAP && VerifySimpleKey())
+  m_tokens.push(Token(Token::VALUE, INPUT.mark()));
+else if (m_flows.top() == FLOW_SEQ)
+  InvalidateSimpleKey();
+  }
+
+  m_simpleKeyAllowed = true;
+  m_canBeJSONFlow = false;
+
+  // eat
+  Mark mark = INPUT.mark();
+  INPUT.eat(1);
+  m_tokens.push(Token(Token::FLOW_ENTRY, mark));
+}
+
+// BlockEntry
+void Scanner::ScanBlockEntry() {
+  // we better be in the block context!
+  if (InFlowContext())
+throw ParserException(INPUT.mark(), ErrorMsg::BLOCK_ENTRY);
+
+  // can we put it here?
+  if (!m_simpleKeyAllowed)
+throw ParserException(INPUT.mark(), ErrorMsg::BLOCK_ENTRY);
+
+  PushIndentTo(INPUT.column(), IndentMarker::SEQ);
+  m_simpleKeyAllowed = true;
+  m_canBeJSONFlow = false;
+
+  // eat
+  Mark mark = INPUT.mark();
+  INPUT.eat(1);
+  m_tokens.push(Token(Token::BLOCK_ENTRY, mark));
+}
+
+// Key
+void Scanner::ScanKey() {
+  // handle keys diffently in the block context (and manage indents)
+  if (InBlockContext()) {
+if (!m_simpleKeyAllowed)
+  throw ParserException(INPUT.mark(), 

[46/51] [abbrv] [partial] nifi-minifi-cpp git commit: MINIFI-68 Adding yaml-cpp source and updating LICENSE to reflect its inclusion.

2016-08-02 Thread aldrin
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/cf813d4d/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/scanscalar.cpp
--
diff --git a/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/scanscalar.cpp 
b/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/scanscalar.cpp
new file mode 100644
index 000..8253b8d
--- /dev/null
+++ b/thirdparty/yaml-cpp-yaml-cpp-0.5.3/src/scanscalar.cpp
@@ -0,0 +1,221 @@
+#include "scanscalar.h"
+
+#include 
+
+#include "exp.h"
+#include "regeximpl.h"
+#include "stream.h"
+#include "yaml-cpp/exceptions.h"  // IWYU pragma: keep
+
+namespace YAML {
+// ScanScalar
+// . This is where the scalar magic happens.
+//
+// . We do the scanning in three phases:
+//   1. Scan until newline
+//   2. Eat newline
+//   3. Scan leading blanks.
+//
+// . Depending on the parameters given, we store or stop
+//   and different places in the above flow.
+std::string ScanScalar(Stream& INPUT, ScanScalarParams& params) {
+  bool foundNonEmptyLine = false;
+  bool pastOpeningBreak = (params.fold == FOLD_FLOW);
+  bool emptyLine = false, moreIndented = false;
+  int foldedNewlineCount = 0;
+  bool foldedNewlineStartedMoreIndented = false;
+  std::size_t lastEscapedChar = std::string::npos;
+  std::string scalar;
+  params.leadingSpaces = false;
+
+  while (INPUT) {
+// 
+// Phase #1: scan until line ending
+
+std::size_t lastNonWhitespaceChar = scalar.size();
+bool escapedNewline = false;
+while (!params.end.Matches(INPUT) && !Exp::Break().Matches(INPUT)) {
+  if (!INPUT)
+break;
+
+  // document indicator?
+  if (INPUT.column() == 0 && Exp::DocIndicator().Matches(INPUT)) {
+if (params.onDocIndicator == BREAK)
+  break;
+else if (params.onDocIndicator == THROW)
+  throw ParserException(INPUT.mark(), ErrorMsg::DOC_IN_SCALAR);
+  }
+
+  foundNonEmptyLine = true;
+  pastOpeningBreak = true;
+
+  // escaped newline? (only if we're escaping on slash)
+  if (params.escape == '\\' && Exp::EscBreak().Matches(INPUT)) {
+// eat escape character and get out (but preserve trailing whitespace!)
+INPUT.get();
+lastNonWhitespaceChar = scalar.size();
+lastEscapedChar = scalar.size();
+escapedNewline = true;
+break;
+  }
+
+  // escape this?
+  if (INPUT.peek() == params.escape) {
+scalar += Exp::Escape(INPUT);
+lastNonWhitespaceChar = scalar.size();
+lastEscapedChar = scalar.size();
+continue;
+  }
+
+  // otherwise, just add the damn character
+  char ch = INPUT.get();
+  scalar += ch;
+  if (ch != ' ' && ch != '\t')
+lastNonWhitespaceChar = scalar.size();
+}
+
+// eof? if we're looking to eat something, then we throw
+if (!INPUT) {
+  if (params.eatEnd)
+throw ParserException(INPUT.mark(), ErrorMsg::EOF_IN_SCALAR);
+  break;
+}
+
+// doc indicator?
+if (params.onDocIndicator == BREAK && INPUT.column() == 0 &&
+Exp::DocIndicator().Matches(INPUT))
+  break;
+
+// are we done via character match?
+int n = params.end.Match(INPUT);
+if (n >= 0) {
+  if (params.eatEnd)
+INPUT.eat(n);
+  break;
+}
+
+// do we remove trailing whitespace?
+if (params.fold == FOLD_FLOW)
+  scalar.erase(lastNonWhitespaceChar);
+
+// 
+// Phase #2: eat line ending
+n = Exp::Break().Match(INPUT);
+INPUT.eat(n);
+
+// 
+// Phase #3: scan initial spaces
+
+// first the required indentation
+while (INPUT.peek() == ' ' && (INPUT.column() < params.indent ||
+   (params.detectIndent && 
!foundNonEmptyLine)))
+  INPUT.eat(1);
+
+// update indent if we're auto-detecting
+if (params.detectIndent && !foundNonEmptyLine)
+  params.indent = std::max(params.indent, INPUT.column());
+
+// and then the rest of the whitespace
+while (Exp::Blank().Matches(INPUT)) {
+  // we check for tabs that masquerade as indentation
+  if (INPUT.peek() == '\t' && INPUT.column() < params.indent &&
+  params.onTabInIndentation == THROW)
+throw ParserException(INPUT.mark(), ErrorMsg::TAB_IN_INDENTATION);
+
+  if (!params.eatLeadingWhitespace)
+break;
+
+  INPUT.eat(1);
+}
+
+// was this an empty line?
+bool nextEmptyLine = Exp::Break().Matches(INPUT);
+bool nextMoreIndented = Exp::Blank().Matches(INPUT);
+if (params.fold == FOLD_BLOCK && foldedNewlineCount == 0 && nextEmptyLine)
+  foldedNewlineStartedMoreIndented = moreIndented;
+
+// for block scalars, we always start with a newline, so we should ignore 
it
+// (not fold or keep)
+if (pastOpeningBreak) {
+  switch (params.fold) {
+case DONT_FOLD:
+  scalar += "\n";
+  break;
+case