Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: pkg/args/lib/src/usage.dart

Issue 12335035: Fix use of stringbuffer in pkg/args (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library args.src.usage; 5 library args.src.usage;
6 6
7 import 'dart:math'; 7 import 'dart:math';
8 8
9 import '../args.dart'; 9 import '../args.dart';
10 10
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 163 }
164 164
165 for (var line in lines) { 165 for (var line in lines) {
166 writeLine(column, line); 166 writeLine(column, line);
167 } 167 }
168 } 168 }
169 169
170 writeLine(int column, String text) { 170 writeLine(int column, String text) {
171 // Write any pending newlines. 171 // Write any pending newlines.
172 while (newlinesNeeded > 0) { 172 while (newlinesNeeded > 0) {
173 buffer.add('\n'); 173 buffer.write('\n');
174 newlinesNeeded--; 174 newlinesNeeded--;
175 } 175 }
176 176
177 // Advance until we are at the right column (which may mean wrapping around 177 // Advance until we are at the right column (which may mean wrapping around
178 // to the next line. 178 // to the next line.
179 while (currentColumn != column) { 179 while (currentColumn != column) {
180 if (currentColumn < NUM_COLUMNS - 1) { 180 if (currentColumn < NUM_COLUMNS - 1) {
181 buffer.add(padRight('', columnWidths[currentColumn])); 181 buffer.write(padRight('', columnWidths[currentColumn]));
182 } else { 182 } else {
183 buffer.add('\n'); 183 buffer.write('\n');
184 } 184 }
185 currentColumn = (currentColumn + 1) % NUM_COLUMNS; 185 currentColumn = (currentColumn + 1) % NUM_COLUMNS;
186 } 186 }
187 187
188 if (column < columnWidths.length) { 188 if (column < columnWidths.length) {
189 // Fixed-size column, so pad it. 189 // Fixed-size column, so pad it.
190 buffer.add(padRight(text, columnWidths[column])); 190 buffer.write(padRight(text, columnWidths[column]));
191 } else { 191 } else {
192 // The last column, so just write it. 192 // The last column, so just write it.
193 buffer.add(text); 193 buffer.write(text);
194 } 194 }
195 195
196 // Advance to the next column. 196 // Advance to the next column.
197 currentColumn = (currentColumn + 1) % NUM_COLUMNS; 197 currentColumn = (currentColumn + 1) % NUM_COLUMNS;
198 198
199 // If we reached the last column, we need to wrap to the next line. 199 // If we reached the last column, we need to wrap to the next line.
200 if (column == NUM_COLUMNS - 1) newlinesNeeded++; 200 if (column == NUM_COLUMNS - 1) newlinesNeeded++;
201 201
202 // Keep track of how many consecutive lines we've written in the last 202 // Keep track of how many consecutive lines we've written in the last
203 // column. 203 // column.
204 if (column == NUM_COLUMNS - 1) { 204 if (column == NUM_COLUMNS - 1) {
205 numHelpLines++; 205 numHelpLines++;
206 } else { 206 } else {
207 numHelpLines = 0; 207 numHelpLines = 0;
208 } 208 }
209 } 209 }
210 210
211 buildAllowedList(Option option) { 211 buildAllowedList(Option option) {
212 var allowedBuffer = new StringBuffer(); 212 var allowedBuffer = new StringBuffer();
213 allowedBuffer.add('['); 213 allowedBuffer.write('[');
214 bool first = true; 214 bool first = true;
215 for (var allowed in option.allowed) { 215 for (var allowed in option.allowed) {
216 if (!first) allowedBuffer.add(', '); 216 if (!first) allowedBuffer.write(', ');
217 allowedBuffer.add(allowed); 217 allowedBuffer.write(allowed);
218 if (allowed == option.defaultValue) { 218 if (allowed == option.defaultValue) {
219 allowedBuffer.add(' (default)'); 219 allowedBuffer.write(' (default)');
220 } 220 }
221 first = false; 221 first = false;
222 } 222 }
223 allowedBuffer.add(']'); 223 allowedBuffer.write(']');
224 return allowedBuffer.toString(); 224 return allowedBuffer.toString();
225 } 225 }
226 } 226 }
227 227
228 /** Pads [source] to [length] by adding spaces at the end. */ 228 /** Pads [source] to [length] by adding spaces at the end. */
229 String padRight(String source, int length) { 229 String padRight(String source, int length) {
230 final result = new StringBuffer(); 230 final result = new StringBuffer();
231 result.add(source); 231 result.write(source);
232 232
233 while (result.length < length) { 233 while (result.length < length) {
234 result.add(' '); 234 result.write(' ');
235 } 235 }
236 236
237 return result.toString(); 237 return result.toString();
238 } 238 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698