|
| 1 | +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 | + |
| 5 | +import 'package:_fe_analyzer_shared/src/messages/codes.dart'; |
| 6 | +import 'package:_fe_analyzer_shared/src/scanner/scanner.dart'; |
| 7 | + |
| 8 | +String codePointToUnicode(int codePoint) { |
| 9 | + // Write unicode value using at least four (but otherwise no more than |
| 10 | + // necessary) hex digits, using uppercase letters. |
| 11 | + // http://www.unicode.org/versions/Unicode10.0.0/appA.pdf |
| 12 | + return "U+${codePoint.toRadixString(16).toUpperCase().padLeft(4, '0')}"; |
| 13 | +} |
| 14 | + |
| 15 | +String formatNumber( |
| 16 | + num num, { |
| 17 | + int? fractionDigits, |
| 18 | + int padWidth = 0, |
| 19 | + bool padWithZeros = false, |
| 20 | +}) { |
| 21 | + String s = fractionDigits == null |
| 22 | + ? '$num' |
| 23 | + : num.toStringAsFixed(fractionDigits); |
| 24 | + return s.padLeft(padWidth, padWithZeros ? '0' : ' '); |
| 25 | +} |
| 26 | + |
| 27 | +String nameOrUnnamed(String name) => name.isEmpty ? '(unnamed)' : name; |
| 28 | + |
| 29 | +String stringOrEmpty(String string) => string.isEmpty ? '(empty)' : string; |
| 30 | + |
| 31 | +String tokenToLexeme(Token token) => token.lexeme; |
| 32 | + |
| 33 | +String validateAndDemangleName(String name) { |
| 34 | + if (name.isEmpty) throw 'No name provided'; |
| 35 | + return demangleMixinApplicationName(name); |
| 36 | +} |
| 37 | + |
| 38 | +String validateAndItemizeNames(List<String> names) { |
| 39 | + if (names.isEmpty) throw 'No names provided'; |
| 40 | + return itemizeNames(names); |
| 41 | +} |
| 42 | + |
| 43 | +String validateCharacter(String character) { |
| 44 | + if (character.runes.length != 1) throw "Not a character '${character}'"; |
| 45 | + return character; |
| 46 | +} |
| 47 | + |
| 48 | +String validateString(String string) { |
| 49 | + if (string.isEmpty) throw 'No string provided'; |
| 50 | + return string; |
| 51 | +} |
0 commit comments