CloneSet54


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

/**
 * Parse the given string and fill info into date object.
 * @param {string} text The string being parsed.
 * @param {Date} date The Date object to hold the parsed date.
 * @param {number} start The position from where parse should begin.
 * @param {boolean} validation If true, input string need to be a valid
 *     date/time string.
 * @return {number} How many characters parser advanced.
 * @private
 */
goog.i18n.DateTimeParse.prototype.internalParse_=
    function (text, date, start, validation){
  var cal=  new goog.i18n.DateTimeParse.MyDate_( );
  var parsePos=  [start];

  // For parsing abutting numeric fields. 'abutPat' is the
  // offset into 'pattern' of the first of 2 or more abutting
  // numeric fields. 'abutStart' is the offset into 'text'
  // where parsing the fields begins. 'abutPass' starts off as 0
  // and increments each time we try to parse the fields.
  var abutPat=  -1; // If >=0, we are in a run of abutting numeric fields
  var abutStart=  0;
  var abutPass=  0;

  for (var i=  0; i<  this.patternParts_.length; i++) {
    if (this.patternParts_[i].count>  0) {
      if (abutPat<  0
          &&             this.patternParts_[i].abutStart) {
        abutPat=  i;
        abutStart=  start;
        abutPass=  0;
                                                          }
      // Handle fields within a run of abutting numeric fields. Take
      // the pattern "HHmmss" as an example. We will try to parse
      // 2/2/2 characters of the input text, then if that fails,
      // 1/2/2. We only adjust the width of the leftmost field; the
      // others remain fixed. This allows "123456" => 12:34:56, but
      // "12345" => 1:23:45. Likewise, for the pattern "yyyyMMdd" we
      // try 4/2/2, 3/2/2, 2/2/2, and finally 1/2/2.
      if (abutPat>=  0) {
        // If we are at the start of a run of abutting fields, then
        // shorten this field in each pass. If we can't shorten
        // this field any more, then the parse of this set of
        // abutting numeric fields has failed.
        var count=  this.patternParts_[i].count;
        if (i==  abutPat) {
          count-=  abutPass;
          abutPass++;
          if (count==  0) {
            // tried all possible width, fail now
            return 0;
                          }
                          }

        if (!this.subParse_(text, parsePos, this.patternParts_[i], count,
                            cal)) {
          // If the parse fails anywhere in the run, back up to the
          // start of the run and retry.
          i=  abutPat-  1;
          parsePos[0]=  abutStart;
          continue;
                                  }
                        }

      // Handle non-numeric fields and non-abutting numeric fields.
      else {
        abutPat=  -1;
        if (!this.subParse_(text, parsePos, this.patternParts_[i], 0, cal)) {
          return 0;
                                                                            }
           }
                                         }
    else   {
      // Handle literal pattern characters. These are any
      // quoted characters and non-alphabetic unquoted
      // characters.
      abutPat=  -1;
      // A run of white space in the pattern matches a run
      // of white space in the input text.
      if (this.patternParts_[i].text.charAt(0)==  ' ') {
        // Advance over run in input text
        var s=  parsePos[0];
        this.skipSpace_(text, parsePos);

        // Must see at least one white space char in input
        if (parsePos[0]>  s) {
          continue;
                             }
                                                       }
      else   if (text.indexOf(this.patternParts_[i].text, parsePos[0])==
                 parsePos[0]) {
        parsePos[0]+=  this.patternParts_[i].text.length;
        continue;
                              }
      // We fall through to this point if the match fails
      return 0;
           }
                                                      }
  // return progress
  return cal.calcDate_(date, validation)
         ?                                 parsePos[0]-  start
         :                                                       0;
                                            } ;
/**
 * Calculate character repeat count in pattern.
 *
 * @param {string} pattern It describes the format of date string that need to
 *     be parsed.
 * @param {number} start The position of pattern character.
 *
 * @return {number} Repeat count.
 * @private
 */
goog.i18n.DateTimeParse.prototype.getNextCharCount_=
    function (pattern, start){
  var ch=  pattern.charAt(start);
  var next=  start+  1;
  while (next<  pattern.length
         &&                       pattern.charAt(next)==  ch) {
    next++;
                                                              }
  return next-  start;
                             } ;
/**
 * All acceptable pattern characters.
 * @private
 */
goog.i18n.DateTimeParse.PATTERN_CHARS_=  'GyMdkHmsSEDahKzZvQ';


/**
 * Pattern characters that specify numerical field.
 * @private
 */
goog.i18n.DateTimeParse.NUMERIC_FORMAT_CHARS_=  'MydhHmsSDkK';


/**
 * Check if the pattern part is a numeric field.
 *
 * @param {Object} part pattern part to be examined.
 *
 * @return {boolean} true if the pattern part is numberic field.
 * @private
 */
goog.i18n.DateTimeParse.prototype.isNumericField_=  function (part){
  if (part.count<=  0) {
    return false;
                       }
  var i=  goog.i18n.DateTimeParse.NUMERIC_FORMAT_CHARS_.indexOf(
      part.text.charAt(0));
  return i>  0
         ||       i==  0
                  &&        part.count<  3;
                                                                   } ;
/**
 * Identify the start of an abutting numeric fields' run. Taking pattern
 * "HHmmss" as an example. It will try to parse 2/2/2 characters of the input
 * text, then if that fails, 1/2/2. We only adjust the width of the leftmost
 * field; the others remain fixed. This allows "123456" => 12:34:56, but
 * "12345" => 1:23:45. Likewise, for the pattern "yyyyMMdd" we try 4/2/2,
 * 3/2/2, 2/2/2, and finally 1/2/2. The first field of connected numeric
 * fields will be marked as abutStart, its width can be reduced to accomodate
 * others.
 *
 * @private
 */
goog.i18n.DateTimeParse.prototype.markAbutStart_=  function ( )
                                                              {
  // abut parts are continuous numeric parts. abutStart is the switch
  // point from non-abut to abut
  var abut=  false;

  for (var i=  0; i<  this.patternParts_.length; i++) {
    if (this.isNumericField_(this.patternParts_[i])) {
      // if next part is not following abut sequence, and isNumericField_
      if (!abut
          &&       i+  1<  this.patternParts_.length
          &&this.isNumericField_(this.patternParts_[i+  1]))
                                                           {
        abut=  true;
        this.patternParts_[i].abutStart=  true;
                                                           }
                                                     }
    else   {
      abut=  false;
           }
                                                      }
                                                              } ;
/**
 * Skip space in the string.
 *
 * @param {string} text input string.
 * @param {Array.<number>} pos where skip start, and return back where the skip
 *     stops.
 * @private
 */
goog.i18n.DateTimeParse.prototype.skipSpace_=  function (text, pos){
  var m=  text.substring(pos[0]).match(/^\s+/);
  if (m) {
    pos[0]+=  m[0].length;
         }
                                                                   } ;


Clone Instance
2
Line Count
185
Source Line
350
Source File
Closure/closure/goog/locale/datetimeparse.js

/**
 * Parse the given string and fill info into date object.
 * @param {string} text The string being parsed.
 * @param {number} start The position from where parse should begin.
 * @param {Date} date The Date object to hold the parsed date.
 * @param {boolean} validation If true, input string need to be a valid
 *     date/time string.
 * @return {number} How many characters parser advanced.
 * @private
 */
goog.locale.DateTimeParse.prototype.internalParse_=
    function (text, start, date, validation){
  var cal=  new goog.locale.DateTimeParse.MyDate_( );
  var parsePos=  [start];

  // For parsing abutting numeric fields. 'abutPat' is the
  // offset into 'pattern' of the first of 2 or more abutting
  // numeric fields. 'abutStart' is the offset into 'text'
  // where parsing the fields begins. 'abutPass' starts off as 0
  // and increments each time we try to parse the fields.
  var abutPat=  -1; // If >=0, we are in a run of abutting numeric fields
  var abutStart=  0;
  var abutPass=  0;

  for (var i=  0; i<  this.patternParts_.length; ++i) {
    if (this.patternParts_[i].count>  0) {
      if (abutPat<  0
          &&             this.patternParts_[i].abutStart) {
        abutPat=  i;
        abutStart=  start;
        abutPass=  0;
                                                          }
      // Handle fields within a run of abutting numeric fields. Take
      // the pattern "HHmmss" as an example. We will try to parse
      // 2/2/2 characters of the input text, then if that fails,
      // 1/2/2. We only adjust the width of the leftmost field; the
      // others remain fixed. This allows "123456" => 12:34:56, but
      // "12345" => 1:23:45. Likewise, for the pattern "yyyyMMdd" we
      // try 4/2/2, 3/2/2, 2/2/2, and finally 1/2/2.
      if (abutPat>=  0) {
        // If we are at the start of a run of abutting fields, then
        // shorten this field in each pass. If we can't shorten
        // this field any more, then the parse of this set of
        // abutting numeric fields has failed.
        var count=  this.patternParts_[i].count;
        if (i==  abutPat) {
          count-=  abutPass;
          abutPass++;
          if (count==  0) {
            // tried all possible width, fail now
            return 0;
                          }
                          }

        if (!this.subParse_(text, parsePos, this.patternParts_[i], count,
                            cal)) {
          // If the parse fails anywhere in the run, back up to the
          // start of the run and retry.
          i=  abutPat-  1;
          parsePos[0]=  abutStart;
          continue;
                                  }
                        }

      // Handle non-numeric fields and non-abutting numeric fields.
      else {
        abutPat=  -1;
        if (!this.subParse_(text, parsePos, this.patternParts_[i], 0, cal)) {
          return 0;
                                                                            }
           }
                                         }
    else   {
      // Handle literal pattern characters. These are any
      // quoted characters and non-alphabetic unquoted
      // characters.
      abutPat=  -1;
      // A run of white space in the pattern matches a run
      // of white space in the input text.
      if (this.patternParts_[i].text.charAt(0)==  ' ') {
        // Advance over run in input text
        var s=  parsePos[0];
        this.skipSpace_(text, parsePos);

        // Must see at least one white space char in input
        if (parsePos[0]>  s) {
          continue;
                             }
                                                       }
      else   if (text.indexOf(this.patternParts_[i].text, parsePos[0])==
                 parsePos[0]) {
        parsePos[0]+=  this.patternParts_[i].text.length;
        continue;
                              }
      // We fall through to this point if the match fails
      return 0;
           }
                                                      }
  // return progress
  return cal.calcDate_(date, validation)
         ?                                 parsePos[0]-  start
         :                                                       0;
                                            } ;
/**
 * Calculate character repeat count in pattern.
 *
 * @param {string} pattern It describes the format of date string that need to
 *     be parsed.
 * @param {number} start the position of pattern character.
 *
 * @return {number} Repeat count.
 * @private
 */
goog.locale.DateTimeParse.prototype.getNextCharCount_=
    function (pattern, start){
  var ch=  pattern.charAt(start);
  var next=  start+  1;
  while (next<  pattern.length
         &&                       pattern.charAt(next)==  ch) {
    ++next;
                                                              }
  return next-  start;
                             } ;
/**
 * All acceptable pattern characters.
 * @private
 */
goog.locale.DateTimeParse.PATTERN_CHARS_=  'GyMdkHmsSEDahKzZv';
/**
 * Pattern characters that specify numerical field.
 * @private
 */
goog.locale.DateTimeParse.NUMERIC_FORMAT_CHARS_=  'MydhHmsSDkK';
/**
 * Check if the pattern part is a numeric field.
 *
 * @param {Object} part pattern part to be examined.
 *
 * @return {boolean} true if the pattern part is numberic field.
 * @private
 */
goog.locale.DateTimeParse.prototype.isNumericField_=  function (part){
  if (part.count<=  0) {
    return false;
                       }
  var i=  goog.locale.DateTimeParse.NUMERIC_FORMAT_CHARS_.indexOf(
      part.text.charAt(0));
  return i>  0
         ||       i==  0
                  &&        part.count<  3;
                                                                     } ;
/**
 * Identify the start of an abutting numeric fields' run. Taking pattern
 * "HHmmss" as an example. It will try to parse 2/2/2 characters of the input
 * text, then if that fails, 1/2/2. We only adjust the width of the leftmost
 * field; the others remain fixed. This allows "123456" => 12:34:56, but
 * "12345" => 1:23:45. Likewise, for the pattern "yyyyMMdd" we try 4/2/2,
 * 3/2/2, 2/2/2, and finally 1/2/2. The first field of connected numeric
 * fields will be marked as abutStart, its width can be reduced to accomodate
 * others.
 *
 * @private
 */
goog.locale.DateTimeParse.prototype.markAbutStart_=  function ( )
                                                                {
  // abut parts are continuous numeric parts. abutStart is the switch
  // point from non-abut to abut
  var abut=  false;

  for (var i=  0; i<  this.patternParts_.length; i++) {
    if (this.isNumericField_(this.patternParts_[i])) {
      // if next part is not following abut sequence, and isNumericField_
      if (!abut
          &&       i+  1<  this.patternParts_.length
          &&this.isNumericField_(this.patternParts_[i+  1]))
                                                           {
        abut=  true;
        this.patternParts_[i].abutStart=  true;
                                                           }
                                                     }
    else   {
      abut=  false;
           }
                                                      }
                                                                } ;
/**
 * Skip space in the string.
 *
 * @param {string} text input string.
 * @param {Array} pos where skip start, and return back where the skip stops.
 * @private
 */
goog.locale.DateTimeParse.prototype.skipSpace_=  function (text, pos){
  var m=  text.substring(pos[0]).match(/^\s+/);
  if (m) {
    pos[0]+=  m[0].length;
         }
                                                                     } ;


Clone AbstractionParameter Count: 6Parameter Bindings

/**
 * Parse the given string and fill info into date object.
 * @param {string} text The string being parsed.
 * @param {number} start The position from where parse should begin.
 * @param {Date} date The Date object to hold the parsed date.
 * @param {boolean} validation If true, input string need to be a valid
 *     date/time string.
 * @return {number} How many characters parser advanced.
 * @private
 */
/**
 * Parse the given string and fill info into date object.
 * @param {string} text The string being parsed.
 * @param {Date} date The Date object to hold the parsed date.
 * @param {number} start The position from where parse should begin.
 * @param {boolean} validation If true, input string need to be a valid
 *     date/time string.
 * @return {number} How many characters parser advanced.
 * @private
 */
goog. [[#variable62c93260]].DateTimeParse.prototype.internalParse_= function (text, [[#variable62c931e0]], [[#variable62c92fa0]],validation)
                                                                    { var cal=new goog. [[#variable62c93260]].DateTimeParse.MyDate_( );
                                                                      var parsePos=[start];
                                                                      // For parsing abutting numeric fields. 'abutPat' is the
                                                                      // offset into 'pattern' of the first of 2 or more abutting
                                                                      // numeric fields. 'abutStart' is the offset into 'text'
                                                                      // where parsing the fields begins. 'abutPass' starts off as 0
                                                                      // and increments each time we try to parse the fields.
                                                                      var abutPat=-1; // If >=0, we are in a run of abutting numeric fields
                                                                      var abutStart=0;
                                                                      var abutPass=0;
                                                                      for (var i=0; i<this.patternParts_.length; [[#variable61a75d00]])
                                                                        { if (this.patternParts_[i].count>0)
                                                                            { if (abutPat<0
                                                                                  && this.patternParts_[i].abutStart)
                                                                                { abutPat=i;
                                                                                  abutStart=start;
                                                                                  abutPass=0;
                                                                                }
                                                                              // Handle fields within a run of abutting numeric fields. Take
                                                                              // the pattern "HHmmss" as an example. We will try to parse
                                                                              // 2/2/2 characters of the input text, then if that fails,
                                                                              // 1/2/2. We only adjust the width of the leftmost field; the
                                                                              // others remain fixed. This allows "123456" => 12:34:56, but
                                                                              // "12345" => 1:23:45. Likewise, for the pattern "yyyyMMdd" we
                                                                              // try 4/2/2, 3/2/2, 2/2/2, and finally 1/2/2.
                                                                              if (abutPat>=0)
                                                                                {
                                                                                  // If we are at the start of a run of abutting fields, then
                                                                                  // shorten this field in each pass. If we can't shorten
                                                                                  // this field any more, then the parse of this set of
                                                                                  // abutting numeric fields has failed.
                                                                                  var count=this.patternParts_[i].count;
                                                                                  if (i==abutPat)
                                                                                    { count-=abutPass;
                                                                                      abutPass++;
                                                                                      if (count==0)
                                                                                        {
                                                                                          // tried all possible width, fail now
                                                                                          return 0;
                                                                                        }
                                                                                    }
                                                                                  if (!this.subParse_(text,parsePos,this.patternParts_[i],count,cal))
                                                                                    {
                                                                                      // If the parse fails anywhere in the run, back up to the
                                                                                      // start of the run and retry.
                                                                                      i=abutPat-1;
                                                                                      parsePos[0]=abutStart;
                                                                                      continue;
                                                                                    }
                                                                                }
                                                                              // Handle non-numeric fields and non-abutting numeric fields.
                                                                              else
                                                                                { abutPat=-1;
                                                                                  if (!this.subParse_(text,parsePos,this.patternParts_[i],0,cal))
                                                                                    { return 0;
                                                                                    }
                                                                                }
                                                                            }
                                                                          else
                                                                            {
                                                                              // Handle literal pattern characters. These are any
                                                                              // quoted characters and non-alphabetic unquoted
                                                                              // characters.
                                                                              abutPat=-1;
                                                                              // A run of white space in the pattern matches a run
                                                                              // of white space in the input text.
                                                                              if (this.patternParts_[i].text.charAt(0)==' ')
                                                                                {
                                                                                  // Advance over run in input text
                                                                                  var s=parsePos[0];
                                                                                  this.skipSpace_(text,parsePos);
                                                                                  // Must see at least one white space char in input
                                                                                  if (parsePos[0]>s)
                                                                                    { continue;
                                                                                    }
                                                                                }
                                                                              else
                                                                                if (text.indexOf(this.patternParts_[i].text,parsePos[0])==parsePos[0])
                                                                                  { parsePos[0]+=this.patternParts_[i].text.length;
                                                                                    continue;
                                                                                  }
                                                                              // We fall through to this point if the match fails
                                                                              return 0;
                                                                            }
                                                                        }
                                                                      // return progress
                                                                      return cal.calcDate_(date,validation)
                                                                             ?parsePos[0]-start
                                                                             : 0;
                                                                    } ;
/**
 * Calculate character repeat count in pattern.
 *
 * @param {string} pattern It describes the format of date string that need to
 *     be parsed.
 * @param {number} start the position of pattern character.
 *
 * @return {number} Repeat count.
 * @private
 */
/**
 * Calculate character repeat count in pattern.
 *
 * @param {string} pattern It describes the format of date string that need to
 *     be parsed.
 * @param {number} start The position of pattern character.
 *
 * @return {number} Repeat count.
 * @private
 */
goog. [[#variable62c93260]].DateTimeParse.prototype.getNextCharCount_= function (pattern,start)
                                                                       { var ch=pattern.charAt(start);
                                                                         var next=start+1;
                                                                         while (next<pattern.length
                                                                                && pattern.charAt(next)==ch)
                                                                           {  [[#variable62c93080]]
                                                                           }
                                                                         return next-start;
                                                                       } ;
/**
 * All acceptable pattern characters.
 * @private
 */
goog. [[#variable62c93260]].DateTimeParse.PATTERN_CHARS_= [[#variable62c92ee0]];
/**
 * Pattern characters that specify numerical field.
 * @private
 */
goog. [[#variable62c93260]].DateTimeParse.NUMERIC_FORMAT_CHARS_='MydhHmsSDkK';
/**
 * Check if the pattern part is a numeric field.
 *
 * @param {Object} part pattern part to be examined.
 *
 * @return {boolean} true if the pattern part is numberic field.
 * @private
 */
goog. [[#variable62c93260]].DateTimeParse.prototype.isNumericField_= function (part)
                                                                     { if (part.count<=0)
                                                                         { return false;
                                                                         }
                                                                       var i=goog. [[#variable62c93260]].DateTimeParse.NUMERIC_FORMAT_CHARS_.indexOf(part.text.charAt(0));
                                                                       return i>0
                                                                              || i==0
                                                                                 && part.count<3;
                                                                     } ;
/**
 * Identify the start of an abutting numeric fields' run. Taking pattern
 * "HHmmss" as an example. It will try to parse 2/2/2 characters of the input
 * text, then if that fails, 1/2/2. We only adjust the width of the leftmost
 * field; the others remain fixed. This allows "123456" => 12:34:56, but
 * "12345" => 1:23:45. Likewise, for the pattern "yyyyMMdd" we try 4/2/2,
 * 3/2/2, 2/2/2, and finally 1/2/2. The first field of connected numeric
 * fields will be marked as abutStart, its width can be reduced to accomodate
 * others.
 *
 * @private
 */
goog. [[#variable62c93260]].DateTimeParse.prototype.markAbutStart_= function ( )
                                                                    {
                                                                      // abut parts are continuous numeric parts. abutStart is the switch
                                                                      // point from non-abut to abut
                                                                      var abut= false;
                                                                      for (var i=0; i<this.patternParts_.length; i++)
                                                                        { if (this.isNumericField_(this.patternParts_[i]))
                                                                            {
                                                                              // if next part is not following abut sequence, and isNumericField_
                                                                              if (!abut
                                                                                  && i+1<this.patternParts_.length
                                                                                  && this.isNumericField_(this.patternParts_[i+1]))
                                                                                { abut= true;
                                                                                  this.patternParts_[i].abutStart= true;
                                                                                }
                                                                            }
                                                                          else
                                                                            { abut= false;
                                                                            }
                                                                        }
                                                                    } ;
/**
 * Skip space in the string.
 *
 * @param {string} text input string.
 * @param {Array} pos where skip start, and return back where the skip stops.
 * @private
 */
/**
 * Skip space in the string.
 *
 * @param {string} text input string.
 * @param {Array.<number>} pos where skip start, and return back where the skip
 *     stops.
 * @private
 */
goog. [[#variable62c93260]].DateTimeParse.prototype.skipSpace_= function (text,pos)
                                                                { var m=text.substring(pos[0]).match(/^\s+/);
                                                                  if (m)
                                                                    { pos[0]+=m[0].length;
                                                                    }
                                                                } ;
 

CloneAbstraction
Parameter Bindings
Parameter
Index
Clone
Instance
Parameter
Name
Value
11[[#62c93260]]
locale 
12[[#62c93260]]
i18n 
21[[#62c931e0]]
start 
22[[#62c931e0]]
date 
31[[#62c92fa0]]
date 
32[[#62c92fa0]]
start 
41[[#61a75d00]]
++i 
42[[#61a75d00]]
i++ 
51[[#62c93080]]
++next; 
52[[#62c93080]]
next++; 
61[[#62c92ee0]]
'GyMdkHmsSEDahKzZv' 
62[[#62c92ee0]]
'GyMdkHmsSEDahKzZvQ'