Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 * @return {boolean} | 105 * @return {boolean} |
| 106 */ | 106 */ |
| 107 String.prototype.isWhitespace = function() | 107 String.prototype.isWhitespace = function() |
| 108 { | 108 { |
| 109 return /^\s*$/.test(this); | 109 return /^\s*$/.test(this); |
| 110 } | 110 } |
| 111 | 111 |
| 112 /** | 112 /** |
| 113 * @return {!Array.<number>} | 113 * @return {!Array.<number>} |
| 114 */ | 114 */ |
| 115 String.prototype.lineEndings = function() | 115 String.prototype.lineEndings = function() |
|
dgozman
2016/03/16 20:36:48
Why don't we remove this method?
lushnikov
2016/03/16 21:04:01
It still comes handy in formatter worker.
| |
| 116 { | 116 { |
| 117 if (!this._lineEndings) { | 117 var endings = this.findAll("\n"); |
| 118 this._lineEndings = this.findAll("\n"); | 118 endings.push(this.length); |
| 119 this._lineEndings.push(this.length); | 119 return endings; |
| 120 } | |
| 121 return this._lineEndings; | |
| 122 } | 120 } |
| 123 | 121 |
| 124 /** | 122 /** |
| 125 * @return {number} | |
| 126 */ | |
| 127 String.prototype.lineCount = function() | |
| 128 { | |
| 129 var lineEndings = this.lineEndings(); | |
| 130 return lineEndings.length; | |
| 131 } | |
| 132 | |
| 133 /** | |
| 134 * @param {number} lineNumber | |
| 135 * @param {number} columNumber | |
| 136 * @return {number} | |
| 137 */ | |
| 138 String.prototype.offsetFromPosition = function(lineNumber, columNumber) | |
| 139 { | |
| 140 return (lineNumber ? this.lineEndings()[lineNumber - 1] + 1 : 0) + columNumb er; | |
| 141 } | |
| 142 | |
| 143 /** | |
| 144 * @return {string} | |
| 145 */ | |
| 146 String.prototype.lineAt = function(lineNumber) | |
| 147 { | |
| 148 var lineEndings = this.lineEndings(); | |
| 149 var lineStart = lineNumber > 0 ? lineEndings[lineNumber - 1] + 1 : 0; | |
| 150 var lineEnd = lineEndings[lineNumber]; | |
| 151 var lineContent = this.substring(lineStart, lineEnd); | |
| 152 if (lineContent.length > 0 && lineContent.charAt(lineContent.length - 1) === "\r") | |
| 153 lineContent = lineContent.substring(0, lineContent.length - 1); | |
| 154 return lineContent; | |
| 155 } | |
| 156 | |
| 157 /** | |
| 158 * @param {string} chars | 123 * @param {string} chars |
| 159 * @return {string} | 124 * @return {string} |
| 160 */ | 125 */ |
| 161 String.prototype.escapeCharacters = function(chars) | 126 String.prototype.escapeCharacters = function(chars) |
| 162 { | 127 { |
| 163 var foundChar = false; | 128 var foundChar = false; |
| 164 for (var i = 0; i < chars.length; ++i) { | 129 for (var i = 0; i < chars.length; ++i) { |
| 165 if (this.indexOf(chars.charAt(i)) !== -1) { | 130 if (this.indexOf(chars.charAt(i)) !== -1) { |
| 166 foundChar = true; | 131 foundChar = true; |
| 167 break; | 132 break; |
| (...skipping 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1666 _tryMerge: function(first, second) | 1631 _tryMerge: function(first, second) |
| 1667 { | 1632 { |
| 1668 var merged = this._mergeCallback && this._mergeCallback(first, second); | 1633 var merged = this._mergeCallback && this._mergeCallback(first, second); |
| 1669 if (!merged) | 1634 if (!merged) |
| 1670 return null; | 1635 return null; |
| 1671 merged.begin = first.begin; | 1636 merged.begin = first.begin; |
| 1672 merged.end = Math.max(first.end, second.end); | 1637 merged.end = Math.max(first.end, second.end); |
| 1673 return merged; | 1638 return merged; |
| 1674 } | 1639 } |
| 1675 } | 1640 } |
| OLD | NEW |