function convertCRLFToLF(context, requiredCrCount, buf) {
  if (!requiredCrCount) { //lucky! no CR prepended, so need not convert.
    return [buf];
  }
  var bufAry = [], startPos = 0, crCount = 0;
  /*
   * Resolve orphan [CR,CR] or [CR] which are produced by previous call of this function.
   * If it is followed by [LF] or [CR,LF], then they together are treated as a [LF],
   * Otherwise, the orphan seq will be output normally.
   */
  if (context.orphanCrCount) {
    var restCrCount = requiredCrCount - context.orphanCrCount;
    // if adbNewLineSeq is found then skip rest CR, start from LF. Otherwise push orphan CR into result
    if (!restCrCount && buf[0] === LF || restCrCount && buf[0] === CR && buf.length > 1 && buf[1] === LF) {
      startPos = restCrCount;
    } else {
      bufAry.push(context.orphanCrCount === 2 ? BUF_CR2 : BUF_CR);
    }
    context.orphanCrCount = 0;
  }

  /*
   * convert CRLF or CRCRLF to LF
   */
  for (var i = startPos; i < buf.length; i++) {
    if (buf[i] === CR) {
      crCount++;

      /*
       *if no more data to match adbNewLineSeq, then save it as orphan CR which will
       *be processed by next call of this function
       */
      if (i + 1 === buf.length) {
        context.orphanCrCount = Math.min(crCount, requiredCrCount);
        //commit data in range from last start position to current position-orphanCrCount
        if (startPos < buf.length - context.orphanCrCount) {
          bufAry.push(buf.slice(startPos, buf.length - context.orphanCrCount));
        }
        return bufAry;
      }
    }
    else {
      /*
       * if found 2 or 2 CR followed by LF, then CR will be discarded.
       * and data before CR will be pushed to result.
       */
      if (crCount >= requiredCrCount && buf[i] === LF) {
        //commit data in range from last start position to current position-requiredCrCount
        bufAry.push(buf.slice(startPos, i - requiredCrCount));
        startPos = i;
      }

      crCount = 0;
    }
  }

  bufAry.push(buf.slice(startPos));
  return bufAry;
}//end of convertCRLFToLF()
/*
 * convert CRLF or CRCRLF to LF, return array of converted buf. Currently, this function only have effect on Windows OS
 */
convert CRLF or CRCRLF to LF, return array of converted buf. Currently, this function only have effect on Windows OS
convert CRLF or CRCRLF to LF return array of converted buf . Currently this function only have effect on Windows OS
function convertCRLFToLF(context, requiredCrCount, buf) {
  if (!requiredCrCount) { 
    return [buf];
  }
  var bufAry = [], startPos = 0, crCount = 0;
  if (context.orphanCrCount) {
    var restCrCount = requiredCrCount - context.orphanCrCount;
    if (!restCrCount && buf[0] === LF || restCrCount && buf[0] === CR && buf.length > 1 && buf[1] === LF) {
      startPos = restCrCount;
    } else {
      bufAry.push(context.orphanCrCount === 2 ? BUF_CR2 : BUF_CR);
    }
    context.orphanCrCount = 0;
  }
  for (var i = startPos; i < buf.length; i++) {
    if (buf[i] === CR) {
      crCount++;
      if (i + 1 === buf.length) {
        context.orphanCrCount = Math.min(crCount, requiredCrCount);
        if (startPos < buf.length - context.orphanCrCount) {
          bufAry.push(buf.slice(startPos, buf.length - context.orphanCrCount));
        }
        return bufAry;
      }
    }
    else {
      if (crCount >= requiredCrCount && buf[i] === LF) {
        bufAry.push(buf.slice(startPos, i - requiredCrCount));
        startPos = i;
      }
      crCount = 0;
    }
  }
  bufAry.push(buf.slice(startPos));
  return bufAry;
}
function convertCRLFToLF ( context , requiredCrCount , buf ) { if ( ! requiredCrCount ) { return [ buf ] ; } var bufAry = [ ] , startPos = 0 , crCount = 0 ; if ( context . orphanCrCount ) { var restCrCount = requiredCrCount - context . orphanCrCount ; if ( ! restCrCount && buf [ 0 ] === LF || restCrCount && buf [ 0 ] === CR && buf . length > 1 && buf [ 1 ] === LF ) { startPos = restCrCount ; } else { bufAry . push ( context . orphanCrCount === 2 ? BUF_CR2 : BUF_CR ) ; } context . orphanCrCount = 0 ; } for ( var i = startPos ; i < buf . length ; i ++ ) { if ( buf [ i ] === CR ) { crCount ++ ; if ( i + 1 === buf . length ) { context . orphanCrCount = Math . min ( crCount , requiredCrCount ) ; if ( startPos < buf . length - context . orphanCrCount ) { bufAry . push ( buf . slice ( startPos , buf . length - context . orphanCrCount ) ) ; } return bufAry ; } } else { if ( crCount >= requiredCrCount && buf [ i ] === LF ) { bufAry . push ( buf . slice ( startPos , i - requiredCrCount ) ) ; startPos = i ; } crCount = 0 ; } } bufAry . push ( buf . slice ( startPos ) ) ; return bufAry ; }
convert CRLF or CRCRLF to LF, return array of converted buf.
convert CRLF or CRCRLF to LF return array of converted buf .
//lucky! no CR prepended, so need not convert. /*
   * Resolve orphan [CR,CR] or [CR] which are produced by previous call of this function.
   * If it is followed by [LF] or [CR,LF], then they together are treated as a [LF],
   * Otherwise, the orphan seq will be output normally.
   */ // if adbNewLineSeq is found then skip rest CR, start from LF. Otherwise push orphan CR into result /*
   * convert CRLF or CRCRLF to LF
   */ /*
       *if no more data to match adbNewLineSeq, then save it as orphan CR which will
       *be processed by next call of this function
       */ //commit data in range from last start position to current position-orphanCrCount /*
       * if found 2 or 2 CR followed by LF, then CR will be discarded.
       * and data before CR will be pushed to result.
       */ //commit data in range from last start position to current position-requiredCrCount //end of convertCRLFToLF()