当前位置: 首页>>代码示例>>C++>>正文


C++ TextStream::Expect方法代码示例

本文整理汇总了C++中TextStream::Expect方法的典型用法代码示例。如果您正苦于以下问题:C++ TextStream::Expect方法的具体用法?C++ TextStream::Expect怎么用?C++ TextStream::Expect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextStream的用法示例。


在下文中一共展示了TextStream::Expect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: while

MacroDef::eAppendStat MacroDef::AppendMacroExpansion
(TextStream & text)
{
  char c;
  bool stat;
  while (text.Consume(c))
    {
	  if ('%' == c)
		{
		  if (text.Expect ("%"))
			{
			  // escape of '%' character: that's OK
			  _definition.Append (c);
			  _definition.Append (c);
			  continue;
			}

		  int argIdx = 0;
		  for (int digitCount = 0; digitCount < 2; digitCount++)
			{
			  stat = text.Consume(c);
			  if (! stat)
				{
				  return kAppendBadArg;
				}
			  if ((c >= '0') && (c <= '9'))
				{
				  // valid arg values
				  if (0 == digitCount)
					{
					  _definition.Append ('%');
					}
				  _definition.Append (c);
				  argIdx = argIdx*10 + (c - '0');
				  if (argIdx > _numArgs)
					{
					  return kAppendArgRange;
					}
				  continue;
				}
			  else
				{
				  return kAppendBadArg;
				}
			}
		}

	  else
		{
		  _definition.Append (c);
		}
    }
  return kAppendNoError;
}
开发者ID:mcanthony,项目名称:aaf,代码行数:54,代码来源:MacroDef.cpp

示例2: closeParen

ArgSet::eInitArgsStat ArgSet::InitArgs
(TextStream & text,
 int numExpected)
{
  // we'll re-init even if we've been init'd already
  _args.Clear ();

  if (! numExpected)
	{
	  // If no args expected, don't try to consume "()"
	  return kInitNoError;
	}

  if (! text.Expect ("("))
    return kInitNoStartParen;

  while (numExpected--)
    {
      ArgDef thisArg;
      ArgDef::eInitStat stat;

	  if (! text.GetLength())
		return kInitArgsTooFew;

	  //
	  // why did this line cause Purify to
	  // think there was a memory leak?
	  //
      // if (text.Expect(")"))

	  TextStream closeParen (")");
	  if (text.Expect(closeParen))
		{
		  return kInitArgsTooFew;
		}

      stat = thisArg.Init (text);
      switch (stat)
		{
		case ArgDef::kInitBadEscape:
		  return kInitNoEndParen;

		case ArgDef::kInitNotTerminated:
		  return kInitNoEndParen;

		default:
		  // unknown error
		  assert (0);
		  break;

		case ArgDef::kInitNoError:
		  _args.Append (thisArg);
		  break;
		}
    }

  if (! text.Expect(")"))
	{
	  return kInitArgsTooMany;
	}
  
  return kInitNoError;
}
开发者ID:mcanthony,项目名称:aaf,代码行数:63,代码来源:ArgSet.cpp

示例3: Test

void MacroDef::Test ()
{
  //
  // ctor
  //
  MacroDef md;
  assert (0 == md._numArgs);
  assert (0 == md._name.GetLength());
  assert (0 == md._definition.GetLength());

  //
  // Init()
  //
  TextStream name = "mac";
  md.Init (name, 2);
  assert (2 == md._numArgs);
  assert (3 == md._name.GetLength());
  assert (md._name.Snoop("mac"));

  //
  // AppendMacroExpansion()
  //
  TextStream exp;
  eAppendStat aStat;
  TextStream ts;

  exp = "arg %03 too great";
  aStat = md.AppendMacroExpansion (exp);
  assert (kAppendArgRange == aStat);

  exp = "arg %x illegal";
  aStat = md.AppendMacroExpansion (exp);
  assert (kAppendBadArg == aStat);

  md.Init (name, 2);	// re-init to clear out old macro def crap
  assert (0 == md._definition.GetLength());
  exp = "Second=%02, First=%01";
  aStat = md.AppendMacroExpansion (exp);
  assert (kAppendNoError == aStat);
  assert (0 != md._definition.GetLength());
  ts = md._definition;
  assert (ts.GetLength());
  assert (ts.Expect ("Second=%02, First=%01"));
  assert (! ts.GetLength());


  //
  // IsMacro()
  //
  TextStream input;
  bool stat;

  input = "amac";
  stat = md.IsMacro (input);
  assert (! stat);

  input = "macro";
  stat = md.IsMacro (input);
  assert (stat);

  input = "macanudo";
  stat = md.IsMacro (input);
  assert (stat);

  input = "madness";
  stat = md.IsMacro (input);
  assert (! stat);

  //
  // InvokeMacro()
  //
  TextStream output;
  eInvokeMacroStat iStat;
  SourceInfo si ("foo", 2);
  ArgSet as;
  ArgSet::eInitArgsStat iasStat;

  TextStream argText;
  argText = "(ONE!,TWO!,THREE!)";
  iasStat = as.InitArgs (argText, 3);
  assert (ArgSet::kInitNoError == iasStat);
  assert (0 == output.GetLength());

  iStat = md.InvokeMacro(as, output, si);
  assert (kInvokeWrongArgCount == iStat);
  assert (0 == output.GetLength());

  MacroDef md2;
  iStat = md2.InvokeMacro(as, output, si);
  assert (kInvokeNotInited == iStat);

  md2.Init (name, 2);
  iStat = md2.InvokeMacro(as, output, si);
  assert (kInvokeWrongArgCount == iStat);
  assert (0 == output.GetLength());

  argText = "(ONE!,TWO!)";
  iasStat = as.InitArgs (argText, 2);
  assert (ArgSet::kInitNoError == iasStat);
  assert (0 == output.GetLength());
//.........这里部分代码省略.........
开发者ID:mcanthony,项目名称:aaf,代码行数:101,代码来源:MacroDefTest.cpp

示例4:

bool MacroDef::IsMacro
(TextStream & testName) const
{
  return testName.Expect (_name);
}
开发者ID:mcanthony,项目名称:aaf,代码行数:5,代码来源:MacroDef.cpp

示例5: Test

void ArgDef::Test ()
{
  //
  // Init(), GetText()
  //
  ArgDef ad;
  TextStream ts;
  TextStream input;
  eInitStat stat;
  assert (0 == ad._rep.GetLength());

  input = "something";
  stat = ad.Init (input);
  assert (kInitNotTerminated == stat);

  input = "proper)";
  stat = ad.Init (input);
  assert (kInitNoError == stat);
  ts = ad.GetText ();
  assert (0 != ts.GetLength());
  assert (ts.Expect ("proper"));
  assert (0 == ts.GetLength());
  assert (input.Expect (")"));
  assert (0 == input.GetLength());

  input = "(paren in arg)";
  stat = ad.Init (input);
  assert (kInitNoError == stat);
  ts = ad.GetText ();
  assert (0 != ts.GetLength());
  assert (ts.Expect ("(paren in arg"));
  assert (0 == ts.GetLength());
  assert (input.Expect (")"));
  assert (0 == input.GetLength());

  input = "middle arg,yup)";
  stat = ad.Init (input);
  assert (kInitNoError == stat);
  ts = ad.GetText ();
  assert (0 != ts.GetLength());
  assert (ts.Expect ("middle arg"));
  assert (0 == ts.GetLength());
  assert (input.Expect ("yup)"));
  assert (0 == input.GetLength());

  input = "comma in\\, arg, here";
  stat = ad.Init (input);
  assert (kInitNoError == stat);
  ts = ad.GetText ();
  assert (0 != ts.GetLength());
  assert (ts.Expect ("comma in, arg"));
  assert (0 == ts.GetLength());
  assert (input.Expect (" here"));
  assert (0 == input.GetLength());

  input = "  \t\t\n\t  White\tspace in here.,";
  stat = ad.Init (input);
  assert (kInitNoError == stat);
  ts = ad.GetText ();
  assert (0 != ts.GetLength());
  assert (ts.Expect ("White\tspace in here."));
  assert (0 == ts.GetLength());
  assert (0 == input.GetLength());

  input = "bad escape\\";
  stat = ad.Init (input);
  assert (kInitBadEscape == stat);
}
开发者ID:UIKit0,项目名称:aaf,代码行数:68,代码来源:ArgDefTest.cpp


注:本文中的TextStream::Expect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。