Files
sdk/samples-dev/swarm/swarm_ui_lib/util/StringUtils.dart
T
Leaf Petersen 745f112ef6 Opt out some files from null safety.
Opt an initial batch of files under samples, samples-dev,
utils, and runtime/tools/dartfuzz out of null safety in preparation
for switching the flag on by default.

Change-Id: Icdfd52a5a969e678a7205903332f73fe3841c223
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166960
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
2020-10-12 22:15:42 +00:00

37 lines
1.2 KiB
Dart

// Copyright (c) 2011, 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.
// @dart = 2.9
part of utilslib;
/**
* General purpose string manipulation utilities.
*/
class StringUtils {
/**
* Returns either [str], or if [str] is null, the value of [defaultStr].
*/
static String defaultString(String str, [String defaultStr = '']) {
return str == null ? defaultStr : str;
}
/** Parse string to a double, and handle null intelligently */
static double parseDouble(String str, [double ifNull = null]) {
return (str == null) ? ifNull : double.parse(str);
}
/** Parse string to a int, and handle null intelligently */
static int parseInt(String str, [int ifNull = null]) {
return (str == null) ? ifNull : int.parse(str);
}
/** Parse bool to a double, and handle null intelligently */
// TODO(jacobr): corelib should have a boolean parsing method
static bool parseBool(String str, [bool ifNull = null]) {
assert(str == null || str == 'true' || str == 'false');
return (str == null) ? ifNull : (str == 'true');
}
}