OSString constructor

OSString(
  1. String str, [
  2. int flag = DEFAULT_MATCH
])

Get a default String matching behaviour depends on which OS is used or specify flag to override String matching staregy.

Value of flag is assigned by bitwise operation with MATCH_CAPITAL and MATCH_SMALL to enable matching staregy in capital and small letter case. Therefore, if case sensitive detection is preferred, the flag should be configured as MATCH_CAPITAL | MATCH_SMALL.

If the flag assigned as DEFAULT_MATCH, it returns OSString.allCapital for Windows platform and OSString.caseSensitive otherwise.

Implementation

factory OSString(String str, [int flag = DEFAULT_MATCH]) {
  int mode = flag & 0x3;

  if (mode == DEFAULT_MATCH) {
    mode |= MATCH_CAPITAL | (Platform.isWindows ? 0 : MATCH_SMALL);
  }

  return switch (mode) {
    0x3 => OSString.caseSensitive,
    0x2 => OSString.allCapital,
    0x1 => OSString.allSmall,
    _ => throw ArgumentError.value(
      flag,
      "flag",
      "Undefined matching flag combinations",
    ),
  }(str);
}