Jamoma API  0.6.0.a19
TTRegex.cpp
1 /*
2  * TTRegex
3  * Copyright © 2008, Théo de la Hogue & Tim Place
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #include "TTRegex.h"
10 
11 #include <regex>
12 using namespace std;
13 typedef std::regex TTExpression;
14 typedef std::match_results <TTStringIter> TTRegexStringResult;
15 
16 #define EXPRESSION ((TTExpression*)(mExpression))
17 #define mEXPRESSION (*EXPRESSION)
18 
19 #define RESULT ((TTRegexStringResult*)(mResult))
20 #define mRESULT (*RESULT)
21 
22 TTRegex::TTRegex(const char* anExpression, int expectedMatch):
23 mExpression(NULL), mResult(NULL),mExpectedMatch(expectedMatch)
24 {
25  try
26  {
27  mExpression = new TTExpression(anExpression, regex_constants::ECMAScript);
28  }
29  catch (const regex_error& e)
30  {
31  TTLogError("%s caught: ", e.what(), anExpression);
32 
33  if (e.code() == regex_constants::error_brack)
34  TTLogError("The code was error_brack");
35  }
36 
37  mResult = new TTRegexStringResult();
38 }
39 
40 TTRegex::~TTRegex()
41 {
42  delete EXPRESSION;
43  delete RESULT;
44 }
45 
46 TTErr TTRegex::parse(TTStringIter begin, TTStringIter end)
47 {
48  if (regex_search(begin, end, mRESULT, mEXPRESSION))
49  return kTTErrNone;
50 
51  return kTTErrGeneric;
52 }
53 
54 /** Get where start the result */
55 TTStringIter TTRegex::begin()
56 {
57  return mRESULT[mExpectedMatch].first;
58 }
59 
60 /** Get where end the result */
61 TTStringIter TTRegex::end()
62 {
63  return mRESULT[mExpectedMatch].second;
64 }
STL namespace.
void TTFOUNDATION_EXPORT TTLogError(TTImmutableCString message,...)
Platform and host independent method for posting errors.
Definition: TTBase.cpp:572
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
No Error.
Definition: TTBase.h:343