createDocComment static method
Creates a Dart-style documentation comment (doc comment) from a string.
If the comment
is null or empty, returns null.
Single-line comments are prefixed with ///
.
Multi-line comments are formatted with ///
at the beginning of each line.
Example:
StringUtils.createDocComment("This is a user profile.")
// returns "/// This is a user profile."
StringUtils.createDocComment("First line.\nSecond line.")
// returns:
// /// First line.
// /// Second line.
Implementation
static String? createDocComment(String? comment) {
if (comment == null || comment.isEmpty) return null;
final lines = comment.split('\n');
if (lines.length == 1) {
return '/// $comment';
} else {
return '''
/// ${lines.join('\n/// ')}
''';
}
}