RegexMatchExpression.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. "use strict";
  2. var LeafMatchExpression = require('./LeafMatchExpression');
  3. // Autogenerated by cport.py on 2013-09-17 14:37
  4. var RegexMatchExpression = module.exports = function RegexMatchExpression(){
  5. base.call(this);
  6. this._matchType = 'REGEX';
  7. }, klass = RegexMatchExpression, base = LeafMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  8. // File: expression_leaf.h lines: 160-160
  9. klass.MaxPatternSize = 32764;
  10. // File: expression_leaf.h lines: 184-184
  11. proto._flags = undefined;
  12. // File: expression_leaf.h lines: 185-185
  13. proto._re = undefined;
  14. // File: expression_leaf.h lines: 183-183
  15. proto._regex = undefined;
  16. /**
  17. *
  18. * Writes a debug string for this object
  19. * @method debugString
  20. * @param level
  21. *
  22. */
  23. proto.debugString = function debugString(level) {
  24. // File: expression_leaf.cpp lines: 225-234
  25. return this._debugAddSpace( level ) + this.path() + " regex /" + this._regex + "/" + this._flags + (this.getTag() ? ' ' + this.getTag().debugString : '') + "\n";
  26. };
  27. /**
  28. *
  29. * checks if this expression is == to the other
  30. * @method equivalent
  31. * @param other
  32. *
  33. */
  34. proto.equivalent = function equivalent(other) {
  35. // File: expression_leaf.cpp lines: 177-185
  36. return other._matchType == 'REGEX' && this.path() == other.path() && this._regex == other._regex && this._flags == other._flags;
  37. };
  38. /**
  39. *
  40. * Return the _flags property
  41. * @method getFlags
  42. *
  43. */
  44. proto.getFlags = function getFlags(){
  45. // File: expression_leaf.h lines: 180-179
  46. return this._flags;
  47. };
  48. /**
  49. *
  50. * Return the _regex property
  51. * @method getString
  52. * @param
  53. *
  54. */
  55. proto.getString = function getString(){
  56. // File: expression_leaf.h lines: 179-178
  57. return this._regex;
  58. };
  59. /**
  60. *
  61. * Initialize the necessary items
  62. * @method init
  63. * @param path
  64. * @param type
  65. *
  66. */
  67. proto.init = function init(path,regex,flags) {
  68. // File: expression_leaf.cpp lines: 196-205
  69. if(regex.toString().length > klass.MaxPatternSize){
  70. return {'code':'BAD_VALUE', 'desc':'Regular Expression too long.'};
  71. }
  72. this._regex = regex;
  73. this._flags = flags;
  74. this._re = new RegExp(regex,flags);
  75. return this.initPath( path );
  76. };
  77. /**
  78. *
  79. * Check if the input element matches
  80. * @method matchesSingleElement
  81. * @param e
  82. *
  83. */
  84. proto.matchesSingleElement = function matchesSingleElement(e) {
  85. // File: expression_leaf.cpp lines: 208-222
  86. if(e instanceof RegExp){
  87. return e.toString() === this._re.toString();
  88. }
  89. return e && (e.match) && e.match(this._re);
  90. // No support for SYMBOLS currently
  91. };
  92. /**
  93. *
  94. * clone this instance to a new one
  95. * @method shallowClone
  96. *
  97. */
  98. proto.shallowClone = function shallowClone(){
  99. // File: expression_leaf.h lines: 167-170
  100. var e = new RegexMatchExpression();
  101. e.init( this.path(), this._regex, this._flags );
  102. return e;
  103. };