| // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| library dartdoc.utils; |
| |
| String stripComments(String str) { |
| if (str == null) return null; |
| |
| StringBuffer buf = new StringBuffer(); |
| |
| if (str.startsWith('///')) { |
| for (String line in str.split('\n')) { |
| line = line.trimLeft(); |
| if (line.startsWith('/// ')) { |
| buf.write('${line.substring(4)}\n'); |
| } else if (line.startsWith('///')) { |
| buf.write('${line.substring(3)}\n'); |
| } else { |
| buf.write('${line}\n'); |
| } |
| } |
| } else { |
| if (str.startsWith('/**')) { |
| str = str.substring(3); |
| } |
| if (str.endsWith('*/')) { |
| str = str.substring(0, str.length - 2); |
| } |
| str = str.trim(); |
| for (String line in str.split('\n')) { |
| line = line.trimLeft(); |
| if (line.startsWith('* ')) { |
| buf.write('${line.substring(2)}\n'); |
| } else if (line.startsWith('*')) { |
| buf.write('${line.substring(1)}\n'); |
| } else { |
| buf.write('$line\n'); |
| } |
| } |
| } |
| return buf.toString().trim(); |
| } |