home *** CD-ROM | disk | FTP | other *** search
/ One Click 21 (Special) / OC021.iso / Interface / it.dig / scripts / __Packages / mx / utils / StringTokenParser.as < prev   
Encoding:
Text File  |  2006-07-04  |  3.9 KB  |  119 lines

  1. class mx.utils.StringTokenParser
  2. {
  3.    var _source;
  4.    var _skipChars;
  5.    static var tkEOF = -1;
  6.    static var tkSymbol = 0;
  7.    static var tkString = 1;
  8.    static var tkInteger = 2;
  9.    static var tkFloat = 3;
  10.    var _index = 0;
  11.    var _token = "";
  12.    function StringTokenParser(source, skipChars)
  13.    {
  14.       this._source = source;
  15.       this._skipChars = skipChars != undefined ? skipChars : null;
  16.    }
  17.    function get token()
  18.    {
  19.       return this._token;
  20.    }
  21.    function getPos()
  22.    {
  23.       return this._index;
  24.    }
  25.    function nextToken()
  26.    {
  27.       var _loc4_ = undefined;
  28.       var _loc2_ = undefined;
  29.       var _loc3_ = this._source.length;
  30.       this.skipBlanks();
  31.       if(this._index >= _loc3_)
  32.       {
  33.          return mx.utils.StringTokenParser.tkEOF;
  34.       }
  35.       _loc2_ = this._source.charCodeAt(this._index);
  36.       if(_loc2_ >= 65 && _loc2_ <= 90 || _loc2_ >= 97 && _loc2_ <= 122 || _loc2_ >= 192 && _loc2_ <= Infinity || _loc2_ == 95)
  37.       {
  38.          _loc4_ = this._index;
  39.          this._index = this._index + 1;
  40.          _loc2_ = this._source.charCodeAt(this._index);
  41.          while((_loc2_ >= 65 && _loc2_ <= 90 || _loc2_ >= 97 && _loc2_ <= 122 || _loc2_ >= 48 && _loc2_ <= 57 || _loc2_ >= 192 && _loc2_ <= Infinity || _loc2_ == 95) && this._index < _loc3_)
  42.          {
  43.             this._index = this._index + 1;
  44.             _loc2_ = this._source.charCodeAt(this._index);
  45.          }
  46.          this._token = this._source.substring(_loc4_,this._index);
  47.          return mx.utils.StringTokenParser.tkSymbol;
  48.       }
  49.       if(_loc2_ == 34 || _loc2_ == 39)
  50.       {
  51.          this._index = this._index + 1;
  52.          _loc4_ = this._index;
  53.          _loc2_ = this._source.charCodeAt(_loc4_);
  54.          while(_loc2_ != 34 && _loc2_ != 39 && this._index < _loc3_)
  55.          {
  56.             this._index = this._index + 1;
  57.             _loc2_ = this._source.charCodeAt(this._index);
  58.          }
  59.          this._token = this._source.substring(_loc4_,this._index);
  60.          this._index = this._index + 1;
  61.          return mx.utils.StringTokenParser.tkString;
  62.       }
  63.       if(_loc2_ == 45 || _loc2_ >= 48 && _loc2_ <= 57)
  64.       {
  65.          var _loc5_ = mx.utils.StringTokenParser.tkInteger;
  66.          _loc4_ = this._index;
  67.          this._index = this._index + 1;
  68.          _loc2_ = this._source.charCodeAt(this._index);
  69.          while(_loc2_ >= 48 && _loc2_ <= 57 && this._index < _loc3_)
  70.          {
  71.             this._index = this._index + 1;
  72.             _loc2_ = this._source.charCodeAt(this._index);
  73.          }
  74.          if(this._index < _loc3_)
  75.          {
  76.             if(_loc2_ >= 48 && _loc2_ <= 57 || _loc2_ == 46 || _loc2_ == 43 || _loc2_ == 45 || _loc2_ == 101 || _loc2_ == 69)
  77.             {
  78.                _loc5_ = mx.utils.StringTokenParser.tkFloat;
  79.             }
  80.             while((_loc2_ >= 48 && _loc2_ <= 57 || _loc2_ == 46 || _loc2_ == 43 || _loc2_ == 45 || _loc2_ == 101 || _loc2_ == 69) && this._index < _loc3_)
  81.             {
  82.                this._index = this._index + 1;
  83.                _loc2_ = this._source.charCodeAt(this._index);
  84.             }
  85.          }
  86.          this._token = this._source.substring(_loc4_,this._index);
  87.          return _loc5_;
  88.       }
  89.       this._token = this._source.charAt(this._index);
  90.       this._index = this._index + 1;
  91.       return mx.utils.StringTokenParser.tkSymbol;
  92.    }
  93.    function skipBlanks()
  94.    {
  95.       if(this._index < this._source.length)
  96.       {
  97.          var _loc2_ = this._source.charAt(this._index);
  98.          while(_loc2_ == " " || this._skipChars != null && this.skipChar(_loc2_))
  99.          {
  100.             this._index = this._index + 1;
  101.             _loc2_ = this._source.charAt(this._index);
  102.          }
  103.       }
  104.    }
  105.    function skipChar(ch)
  106.    {
  107.       var _loc2_ = 0;
  108.       while(_loc2_ < this._skipChars.length)
  109.       {
  110.          if(ch == this._skipChars[_loc2_])
  111.          {
  112.             return true;
  113.          }
  114.          _loc2_ = _loc2_ + 1;
  115.       }
  116.       return false;
  117.    }
  118. }
  119.