搜尋套件、儲存庫與 APP 分類

GitHub 儲存庫dart-archive/string_scanner

string_scanner

一個使用模式序列解析字串的類別。

string_scanner 專案封面
星標
54
分支
17
最近推送(UTC)
2024年12月17日
專案狀態
已封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

[!IMPORTANT]
This repo has moved to https://github.com/dart-lang/tools/tree/main/pkgs/string_scanner

Dart CI pub package package publisher

This package exposes a StringScanner type that makes it easy to parse a string using a series of Patterns. For example:

import 'dart:math' as math;

import 'package:string_scanner/string_scanner.dart';

num parseNumber(String source) {
  // Scan a number ("1", "1.5", "-3").
  final scanner = StringScanner(source);

  // [Scanner.scan] tries to consume a [Pattern] and returns whether or not it
  // succeeded. It will move the scan pointer past the end of the pattern.
  final negative = scanner.scan('-');

  // [Scanner.expect] consumes a [Pattern] and throws a [FormatError] if it
  // fails. Like [Scanner.scan], it will move the scan pointer forward.
  scanner.expect(RegExp(r'\d+'));

  // [Scanner.lastMatch] holds the [MatchData] for the most recent call to
  // [Scanner.scan], [Scanner.expect], or [Scanner.matches].
  var number = num.parse(scanner.lastMatch![0]!);

  if (scanner.scan('.')) {
    scanner.expect(RegExp(r'\d+'));
    final decimal = scanner.lastMatch![0]!;
    number += int.parse(decimal) / math.pow(10, decimal.length);
  }

  // [Scanner.expectDone] will throw a [FormatError] if there's any input that
  // hasn't yet been consumed.
  scanner.expectDone();

  return (negative ? -1 : 1) * number;
}
Dart Archive GitHub avatar
GitHub 作者

Dart Archive ↗

Legacy projects kept around for posterity – See github.com/dart-lang for current work

語言Dart

使用的依賴

依賴清單 3 項

  • source_span^1.8.0
  • dart_flutter_team_lints開發依賴^3.0.0
  • test開發依賴^1.16.6

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗