CloneSet52


Previous CloneSetNext CloneSetBack to Main Report
Clone
Mass
Clones in
CloneSet
Parameter
Count
Clone
Similarity
Syntax Category
[Sequence Length]
195260.973SourceElements[7]
Clone AbstractionParameter Bindings
Clone Instance
(Click to see clone)
Line CountSource Line
Source File
1202693
Closure/closure/goog/i18n/datetimeparse.js
2195701
Closure/closure/goog/locale/datetimeparse.js
Clone Instance
1
Line Count
202
Source Line
693
Source File
Closure/closure/goog/i18n/datetimeparse.js

/**
 * Parse Day of week field.
 * @param {string} text the time text to be parsed.
 * @param {Array.<number>} pos Parse position.
 * @param {goog.i18n.DateTimeParse.MyDate_} cal object to hold parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog.i18n.DateTimeParse.prototype.subParseDayOfWeek_=
    function (text, pos, cal){
  // Handle both short and long forms.
  // Try count == 4 (DDDD) first:
  var value=  this.matchString_(text, pos, goog.i18n.DateTimeSymbols.WEEKDAYS);
  if (value<  0) {
    value=  this.matchString_(text, pos,
                              goog.i18n.DateTimeSymbols.SHORTWEEKDAYS);
                 }
  if (value<  0) {
    return false;
                 }
  cal.dayOfWeek=  value;
  return true;
                             } ;


/**
 * Parse fractional seconds field.
 *
 * @param {number} value parsed numberic value.
 * @param {Array.<number>} pos current parse position.
 * @param {number} start where this field start.
 * @param {goog.i18n.DateTimeParse.MyDate_} cal object to hold parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog.i18n.DateTimeParse.prototype.subParseFractionalSeconds_=
    function (value, pos, start, cal){
  // Fractional seconds left-justify
  var len=  pos[0]-  start;
  cal.milliseconds=  len<  3
                     ?         value*  Math.pow(10, 3-  len)
                     :         Math.round(value/  Math.pow(10, len-  3));
  return true;
                                     } ;

/**
 * Parse GMT type timezone.
 *
 * @param {string} text the time text to be parsed.
 * @param {Array.<number>} pos Parse position.
 * @param {goog.i18n.DateTimeParse.MyDate_} cal object to hold parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog.i18n.DateTimeParse.prototype.subparseTimeZoneInGMT_=
    function (text, pos, cal){
  // First try to parse generic forms such as GMT-07:00. Do this first
  // in case localized DateFormatZoneData contains the string "GMT"
  // for a zone; in that case, we don't want to match the first three
  // characters of GMT+/-HH:MM etc.

  // For time zones that have no known names, look for strings
  // of the form:
  //    GMT[+-]hours:minutes or
  //    GMT[+-]hhmm or
  //    GMT.
  if (text.indexOf('GMT', pos[0])==  pos[0]) {
    pos[0]+=  3;  // 3 is the length of GMT
    return this.parseTimeZoneOffset_(text, pos, cal);
                                             }

  // TODO: check for named time zones by looking through the locale
  // data from the DateFormatZoneData strings. should parse both short and long
  // forms.
  // subParseZoneString(text, start, cal);

  // As a last resort, look for numeric timezones of the form
  // [+-]hhmm as specified by RFC 822.  This code is actually
  // a little more permissive than RFC 822.  It will try to do
  // its best with numbers that aren't strictly 4 digits long.
  return this.parseTimeZoneOffset_(text, pos, cal);
                             } ;


/**
 * Parse time zone offset.
 *
 * @param {string} text the time text to be parsed.
 * @param {Array.<number>} pos Parse position.
 * @param {goog.i18n.DateTimeParse.MyDate_} cal object to hold parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog.i18n.DateTimeParse.prototype.parseTimeZoneOffset_=
    function (text, pos, cal){
  if (pos[0]>=  text.length) {
    cal.tzOffset=  0;
    return true;
                             }

  var sign=  1;
  switch (text.charAt(pos[0]))
  { case '-': sign=  -1;  // fall through
    case '+': pos[0]++; }


  // Look for hours:minutes or hhmm.
  var st=  pos[0];
  var value=  this.parseInt_(text, pos);
  if (value==  0
      &&            pos[0]==  st) {
    return false;
                                  }
  var offset;
  if (pos[0]<  text.length
      &&                      text.charAt(pos[0])==  ':') {
    // This is the hours:minutes case
    offset=  value*  60;
    pos[0]++;
    st=  pos[0];
    value=  this.parseInt_(text, pos);
    if (value==  0
        &&            pos[0]==  st) {
      return false;
                                    }
    offset+=  value;
                                                          }
  else   {
    // This is the hhmm case.
    offset=  value;
    // Assume "-23".."+23" refers to hours.
    if (offset<  24
        &&             (pos[0]-  st)<=  2) {
      offset *= 60;
                                           }
    else   {
      // todo: this looks questionable, should have more error checking
      offset=  offset%  100+  offset/  100*  60;
           }
         }
  offset *= sign;
  cal.tzOffset=  -offset;
  return true;
                             } ;
/**
 * Parse a integer string and return integer value.
 *
 * @param {string} text string being parsed.
 * @param {Array.<number>} pos parse position.
 *
 * @return {number} Converted integer value.
 * @private
 */
goog.i18n.DateTimeParse.prototype.parseInt_=  function (text, pos){
  var m=  text.substring(pos[0]).match(/^\d+/);
  if (!m) {
    return -1;
          }
  pos[0]+=  m[0].length;
  return parseInt(m[0], 10);
                                                                  } ;
/**
 * Attempt to match the text at a given position against an array of strings.
 * Since multiple strings in the array may match (for example, if the array
 * contains "a", "ab", and "abc", all will match the input string "abcd") the
 * longest match is returned.
 *
 * @param {string} text The string to match to.
 * @param {Array.<number>} pos parsing position.
 * @param {Array.<string>} data The string array of matching patterns.
 *
 * @return {number} the new start position if matching succeeded; a negative
 *     number indicating matching failure.
 * @private
 */
goog.i18n.DateTimeParse.prototype.matchString_=  function (text, pos, data){
  // There may be multiple strings in the data[] array which begin with
  // the same prefix (e.g., Cerven and Cervenec (June and July) in Czech).
  // We keep track of the longest match, and return that. Note that this
  // unfortunately requires us to test all array elements.
  var bestMatchLength=  0;
  var bestMatch=  -1;
  var lower_text=  text.substring(pos[0]).toLowerCase( );
  for (var i=  0; i<  data.length; i++) {
    var len=  data[i].length;
    // Always compare if we have no match yet; otherwise only compare
    // against potentially better matches (longer strings).
    if (len>  bestMatchLength
        &&lower_text.indexOf(data[i].toLowerCase( ))== 0)
                                                        {
      bestMatch=  i;
      bestMatchLength=  len;
                                                        }
                                        }
  if (bestMatch>=  0) {
    pos[0]+=  bestMatchLength;
                      }
  return bestMatch;
                                                                           } ;

/**
 * This class hold the intermediate parsing result. After all fields are
 * consumed, final result will be resolved from this class.
 * @constructor
 * @private
 */
goog.i18n.DateTimeParse.MyDate_=  function ( )
                                            {} ;


Clone Instance
2
Line Count
195
Source Line
701
Source File
Closure/closure/goog/locale/datetimeparse.js

/**
 * Parse Day of week field.
 * @param {string} text the time text to be parsed.
 * @param {Array} pos Parse position.
 * @param {Object} cal MyDate_ object that holds parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog.locale.DateTimeParse.prototype.subParseDayOfWeek_=
    function (text, pos, cal){
  // Handle both short and long forms.
  // Try count == 4 (DDDD) first:
  var value=  this.matchString_(text, pos, this.symbols_.WEEKDAYS);
  if (value<  0) {
    value=  this.matchString_(text, pos, this.symbols_.SHORTWEEKDAYS);
                 }
  if (value<  0) {
    return false;
                 }
  cal.dayOfWeek=  value;
  return true;
                             } ;

/**
 * Parse fractional seconds field.
 *
 * @param {number} value parsed numberic value.
 * @param {Array} pos current parse position.
 * @param {number} start where this field start.
 * @param {Object} cal MyDate_ object that holds parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog.locale.DateTimeParse.prototype.subParseFractionalSeconds_=
    function (value, pos, start, cal){
  // Fractional seconds left-justify
  var len=  pos[0]-  start;
  cal.milliseconds=  len<  3
                     ?         value*  Math.pow(10, 3-  len)
                     :         Math.round(value/  Math.pow(10, len-  3));
  return true;
                                     } ;
/**
 * Parse GMT type timezone.
 *
 * @param {string} text the time text to be parsed.
 * @param {Array} pos Parse position.
 * @param {Object} cal MyDate_ object that holds parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog.locale.DateTimeParse.prototype.subparseTimeZoneInGMT_=
    function (text, pos, cal){
  // First try to parse generic forms such as GMT-07:00. Do this first
  // in case localized DateFormatZoneData contains the string "GMT"
  // for a zone; in that case, we don't want to match the first three
  // characters of GMT+/-HH:MM etc.

  // For time zones that have no known names, look for strings
  // of the form:
  //    GMT[+-]hours:minutes or
  //    GMT[+-]hhmm or
  //    GMT.
  if (text.indexOf('GMT', pos[0])==  pos[0]) {
    pos[0]+=  3;  // 3 is the length of GMT
    return this.parseTimeZoneOffset_(text, pos, cal);
                                             }

  // TODO: check for named time zones by looking through the locale
  // data from the DateFormatZoneData strings. should parse both short and long
  // forms.
  // subParseZoneString(text, start, cal);

  // As a last resort, look for numeric timezones of the form
  // [+-]hhmm as specified by RFC 822.  This code is actually
  // a little more permissive than RFC 822.  It will try to do
  // its best with numbers that aren't strictly 4 digits long.
  return this.parseTimeZoneOffset_(text, pos, cal);
                             } ;

/**
 * Parse time zone offset.
 *
 * @param {string} text the time text to be parsed.
 * @param {Array} pos Parse position.
 * @param {Object} cal MyDate_ object that holds parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog.locale.DateTimeParse.prototype.parseTimeZoneOffset_=
    function (text, pos, cal){
  if (pos[0]>=  text.length) {
    cal.tzOffset=  0;
    return true;
                             }

  var sign=  1;
  switch (text.charAt(pos[0]))
  { case '-': sign=  -1;  // fall through
    case '+': pos[0]++; }


  // Look for hours:minutes or hhmm.
  var st=  pos[0];
  var value=  this.parseInt_(text, pos);
  if (value==  0
      &&            pos[0]==  st) {
    return false;
                                  }
  var offset;
  if (pos[0]<  text.length
      &&                      text.charAt(pos[0])==  ':') {
    // This is the hours:minutes case
    offset=  value*  60;
    pos[0]++;
    st=  pos[0];
    value=  this.parseInt_(text, pos);
    if (value==  0
        &&            pos[0]==  st) {
      return false;
                                    }
    offset+=  value;
                                                          }
  else   {
    // This is the hhmm case.
    offset=  value;
    // Assume "-23".."+23" refers to hours.
    if (offset<  24
        &&             (pos[0]-  st)<=  2)
        offset *= 60;
    else
      // todo: this looks questionable, should have more error checking
      offset=  offset%  100+  offset/  100*  60;
         }
  offset *= sign;
  cal.tzOffset=  -offset;
  return true;
                             } ;
/**
 * Parse a integer string and return integer value.
 *
 * @param {string} text string being parsed.
 * @param {Array} pos parse position.
 *
 * @return {number} Converted integer value.
 * @private
 */
goog.locale.DateTimeParse.prototype.parseInt_=  function (text, pos){
  var m=  text.substring(pos[0]).match(/^\d+/);
  if (!m) {
    return -1;
          }
  pos[0]+=  m[0].length;
  return parseInt(m[0], 10);
                                                                    } ;
/**
 * Attempt to match the text at a given position against an array of strings.
 * Since multiple strings in the array may match (for example, if the array
 * contains "a", "ab", and "abc", all will match the input string "abcd") the
 * longest match is returned.
 *
 * @param {string} text The string to match to.
 * @param {Array} pos parsing position.
 * @param {Array} data The string array that is used to found match from.
 *
 * @return {number} the new start position if matching succeeded; a negative
 *     number indicating matching failure.
 * @private
 */
goog.locale.DateTimeParse.prototype.matchString_=  function (text, pos, data){
  // There may be multiple strings in the data[] array which begin with
  // the same prefix (e.g., Cerven and Cervenec (June and July) in Czech).
  // We keep track of the longest match, and return that. Note that this
  // unfortunately requires us to test all array elements.
  var bestMatchLength=  0;
  var bestMatch=  -1;
  var lower_text=  text.substring(pos[0]).toLowerCase( );
  for (var i=  0; i<  data.length; ++i) {
    var len=  data[i].length;
    // Always compare if we have no match yet; otherwise only compare
    // against potentially better matches (longer strings).
    if (len>  bestMatchLength
        &&lower_text.indexOf(data[i].toLowerCase( ))== 0)
                                                        {
      bestMatch=  i;
      bestMatchLength=  len;
                                                        }
                                        }
  if (bestMatch>=  0) {
    pos[0]+=  bestMatchLength;
                      }
  return bestMatch;
                                                                             } ;
/**
 * This class hold the intermediate parsing result. After all fields are
 * consumed, final result will be resolved from this class.
 * @constructor
 * @private
 */
goog.locale.DateTimeParse.MyDate_=  function ( )
                                              {} ;


Clone AbstractionParameter Count: 6Parameter Bindings

/**
 * Parse Day of week field.
 * @param {string} text the time text to be parsed.
 * @param {Array} pos Parse position.
 * @param {Object} cal MyDate_ object that holds parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
/**
 * Parse Day of week field.
 * @param {string} text the time text to be parsed.
 * @param {Array.<number>} pos Parse position.
 * @param {goog.i18n.DateTimeParse.MyDate_} cal object to hold parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog. [[#variable20b9c880]].DateTimeParse.prototype.subParseDayOfWeek_= function (text,pos,cal)
                                                                        {
                                                                          // Handle both short and long forms.
                                                                          // Try count == 4 (DDDD) first:
                                                                          var value=this.matchString_(text,pos, [[#variable20b9c900]]. [[#variable20b9c740]].WEEKDAYS);
                                                                          if (value<0)
                                                                            { value=this.matchString_(text,pos, [[#variable20b9c900]]. [[#variable20b9c740]].SHORTWEEKDAYS);
                                                                            }
                                                                          if (value<0)
                                                                            { return false;
                                                                            }
                                                                          cal.dayOfWeek=value;
                                                                          return true;
                                                                        } ;
/**
 * Parse fractional seconds field.
 *
 * @param {number} value parsed numberic value.
 * @param {Array} pos current parse position.
 * @param {number} start where this field start.
 * @param {Object} cal MyDate_ object that holds parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
/**
 * Parse fractional seconds field.
 *
 * @param {number} value parsed numberic value.
 * @param {Array.<number>} pos current parse position.
 * @param {number} start where this field start.
 * @param {goog.i18n.DateTimeParse.MyDate_} cal object to hold parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog. [[#variable20b9c880]].DateTimeParse.prototype.subParseFractionalSeconds_= function (value,pos,start,cal)
                                                                                {
                                                                                  // Fractional seconds left-justify
                                                                                  var len=pos[0]-start;
                                                                                  cal.milliseconds=len<3
                                                                                                   ?value*Math.pow(10,3-len)
                                                                                                   :Math.round(value/Math.pow(10,len-3));
                                                                                  return true;
                                                                                } ;
/**
 * Parse GMT type timezone.
 *
 * @param {string} text the time text to be parsed.
 * @param {Array} pos Parse position.
 * @param {Object} cal MyDate_ object that holds parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
/**
 * Parse GMT type timezone.
 *
 * @param {string} text the time text to be parsed.
 * @param {Array.<number>} pos Parse position.
 * @param {goog.i18n.DateTimeParse.MyDate_} cal object to hold parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog. [[#variable20b9c880]].DateTimeParse.prototype.subparseTimeZoneInGMT_= function (text,pos,cal)
                                                                            {
                                                                              // First try to parse generic forms such as GMT-07:00. Do this first
                                                                              // in case localized DateFormatZoneData contains the string "GMT"
                                                                              // for a zone; in that case, we don't want to match the first three
                                                                              // characters of GMT+/-HH:MM etc.
                                                                              // For time zones that have no known names, look for strings
                                                                              // of the form:
                                                                              //    GMT[+-]hours:minutes or
                                                                              //    GMT[+-]hhmm or
                                                                              //    GMT.
                                                                              if (text.indexOf('GMT',pos[0])==pos[0])
                                                                                { pos[0]+=3; // 3 is the length of GMT
                                                                                  return this.parseTimeZoneOffset_(text,pos,cal);
                                                                                }
                                                                              // TODO: check for named time zones by looking through the locale
                                                                              // data from the DateFormatZoneData strings. should parse both short and long
                                                                              // forms.
                                                                              // subParseZoneString(text, start, cal);
                                                                              // As a last resort, look for numeric timezones of the form
                                                                              // [+-]hhmm as specified by RFC 822.  This code is actually
                                                                              // a little more permissive than RFC 822.  It will try to do
                                                                              // its best with numbers that aren't strictly 4 digits long.
                                                                              return this.parseTimeZoneOffset_(text,pos,cal);
                                                                            } ;
/**
 * Parse time zone offset.
 *
 * @param {string} text the time text to be parsed.
 * @param {Array} pos Parse position.
 * @param {Object} cal MyDate_ object that holds parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
/**
 * Parse time zone offset.
 *
 * @param {string} text the time text to be parsed.
 * @param {Array.<number>} pos Parse position.
 * @param {goog.i18n.DateTimeParse.MyDate_} cal object to hold parsed value.
 *
 * @return {boolean} True if successful.
 * @private
 */
goog. [[#variable20b9c880]].DateTimeParse.prototype.parseTimeZoneOffset_= function (text,pos,cal)
                                                                          { if (pos[0]>=text.length)
                                                                              { cal.tzOffset=0;
                                                                                return true;
                                                                              }
                                                                            var sign=1;
                                                                            switch (text.charAt(pos[0]))
                                                                            { case '-':
                                                                                sign=-1; // fall through
                                                                              case '+':
                                                                                pos[0]++; }
                                                                            // Look for hours:minutes or hhmm.
                                                                            var st=pos[0];
                                                                            var value=this.parseInt_(text,pos);
                                                                            if (value==0
                                                                                && pos[0]==st)
                                                                              { return false;
                                                                              }
                                                                            var offset;
                                                                            if (pos[0]<text.length
                                                                                && text.charAt(pos[0])==':')
                                                                              {
                                                                                // This is the hours:minutes case
                                                                                offset=value*60;
                                                                                pos[0]++;
                                                                                st=pos[0];
                                                                                value=this.parseInt_(text,pos);
                                                                                if (value==0
                                                                                    && pos[0]==st)
                                                                                  { return false;
                                                                                  }
                                                                                offset+=value;
                                                                              }
                                                                            else
                                                                              {
                                                                                // This is the hhmm case.
                                                                                offset=value;
                                                                                // Assume "-23".."+23" refers to hours.
                                                                                if (offset<24
                                                                                    && (pos[0]-st)<=2)
                                                                                   [[#variable20b9c5c0]]
                                                                                else
                                                                                   [[#variable20b9c5a0]]
                                                                              }
                                                                            offset *= sign;
                                                                            cal.tzOffset=-offset;
                                                                            return true;
                                                                          } ;
/**
 * Parse a integer string and return integer value.
 *
 * @param {string} text string being parsed.
 * @param {Array} pos parse position.
 *
 * @return {number} Converted integer value.
 * @private
 */
/**
 * Parse a integer string and return integer value.
 *
 * @param {string} text string being parsed.
 * @param {Array.<number>} pos parse position.
 *
 * @return {number} Converted integer value.
 * @private
 */
goog. [[#variable20b9c880]].DateTimeParse.prototype.parseInt_= function (text,pos)
                                                               { var m=text.substring(pos[0]).match(/^\d+/);
                                                                 if (!m)
                                                                   { return -1;
                                                                   }
                                                                 pos[0]+=m[0].length;
                                                                 return parseInt(m[0],10);
                                                               } ;
/**
 * Attempt to match the text at a given position against an array of strings.
 * Since multiple strings in the array may match (for example, if the array
 * contains "a", "ab", and "abc", all will match the input string "abcd") the
 * longest match is returned.
 *
 * @param {string} text The string to match to.
 * @param {Array} pos parsing position.
 * @param {Array} data The string array that is used to found match from.
 *
 * @return {number} the new start position if matching succeeded; a negative
 *     number indicating matching failure.
 * @private
 */
/**
 * Attempt to match the text at a given position against an array of strings.
 * Since multiple strings in the array may match (for example, if the array
 * contains "a", "ab", and "abc", all will match the input string "abcd") the
 * longest match is returned.
 *
 * @param {string} text The string to match to.
 * @param {Array.<number>} pos parsing position.
 * @param {Array.<string>} data The string array of matching patterns.
 *
 * @return {number} the new start position if matching succeeded; a negative
 *     number indicating matching failure.
 * @private
 */
goog. [[#variable20b9c880]].DateTimeParse.prototype.matchString_= function (text,pos,data)
                                                                  {
                                                                    // There may be multiple strings in the data[] array which begin with
                                                                    // the same prefix (e.g., Cerven and Cervenec (June and July) in Czech).
                                                                    // We keep track of the longest match, and return that. Note that this
                                                                    // unfortunately requires us to test all array elements.
                                                                    var bestMatchLength=0;
                                                                    var bestMatch=-1;
                                                                    var lower_text=text.substring(pos[0]).toLowerCase( );
                                                                    for (var i=0; i<data.length; [[#variable20b9c4a0]])
                                                                      { var len=data[i].length;
                                                                        // Always compare if we have no match yet; otherwise only compare
                                                                        // against potentially better matches (longer strings).
                                                                        if (len>bestMatchLength
                                                                            && lower_text.indexOf(data[i].toLowerCase( ))==0)
                                                                          { bestMatch=i;
                                                                            bestMatchLength=len;
                                                                          }
                                                                      }
                                                                    if (bestMatch>=0)
                                                                      { pos[0]+=bestMatchLength;
                                                                      }
                                                                    return bestMatch;
                                                                  } ;
/**
 * This class hold the intermediate parsing result. After all fields are
 * consumed, final result will be resolved from this class.
 * @constructor
 * @private
 */
goog. [[#variable20b9c880]].DateTimeParse.MyDate_= function ( )
                                                   {} ;
 

CloneAbstraction
Parameter Bindings
Parameter
Index
Clone
Instance
Parameter
Name
Value
11[[#20b9c880]]
locale 
12[[#20b9c880]]
i18n 
21[[#20b9c900]]
this 
22[[#20b9c900]]
goog.i18n 
31[[#20b9c740]]
symbols_ 
32[[#20b9c740]]
DateTimeSymbols 
41[[#20b9c5c0]]
offset *= 60; 
42[[#20b9c5c0]]
{ offset *= 60;
} 
51[[#20b9c5a0]]
// todo: this looks questionable, should have more error checking
offset=offset%100+offset/100*60; 
52[[#20b9c5a0]]
{
  // todo: this looks questionable, should have more error checking
  offset=offset%100+offset/100*60;
} 
61[[#20b9c4a0]]
++i 
62[[#20b9c4a0]]
i++