-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Dart CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: dart:stable | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install dependencies | ||
run: dart pub get | ||
- name: Formatter | ||
run: dart format --output none --set-exit-if-changed example lib test | ||
- name: Analyzer | ||
run: dart analyze --fatal-infos --fatal-warnings | ||
- name: Tests | ||
run: dart test --coverage=.coverage | ||
- name: Coverage | ||
run: dart run coverage:format_coverage -l -c -i .coverage --report-on=lib --packages=.dart_tool/package_config.json | dart run check_coverage:check_coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# .github/workflows/publish.yml | ||
name: Publish to pub.dev | ||
|
||
on: | ||
push: | ||
tags: | ||
- '[0-9]+.[0-9]+.[0-9]+*' # tag-pattern on pub.dev: 'v' | ||
|
||
# Publish using the reusable workflow from dart-lang. | ||
jobs: | ||
publish: | ||
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## [0.1.0] - 2023-10-10 | ||
### Added | ||
- Initial release | ||
|
||
[0.1.0]: https://github.com/f3ath/dart-quoted-string/releases/tag/0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
include: package:lints/recommended.yaml | ||
|
||
linter: | ||
rules: | ||
- sort_constructors_first | ||
- sort_unnamed_constructors_first |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:quoted_string/quoted_string.dart'; | ||
|
||
void main() { | ||
// "Quote (\") and backslash (\\)" | ||
print(r'Quote (") and backslash (\)'.quote()); | ||
|
||
// Quote (") and backslash (\) | ||
print(r'"Quote (\") and backslash (\\)"'.unquote()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
extension QuotedString on String { | ||
/// Encloses the string into double quotes. Escapes the content if necessary. | ||
String quote() => '"${replaceAll(r'\', r'\\').replaceAll('"', r'\"')}"'; | ||
|
||
/// Removes the quotes around the string and unescapes it. | ||
/// If this string is not a quoted string, returns it unchanged. | ||
String unquote() { | ||
if (length < 2 || !startsWith('"') || !endsWith('"')) return this; | ||
final buf = StringBuffer(); | ||
for (var i = 1; i < length - 1; i++) { | ||
if (this[i] == r'\') { | ||
if (i > length - 3) return this; | ||
i++; | ||
} | ||
buf.write(this[i]); | ||
} | ||
return buf.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: quoted_string | ||
description: String quoting/unquoting. | ||
version: 0.1.0 | ||
repository: https://github.com/f3ath/dart-quoted-string | ||
|
||
environment: | ||
sdk: '>=3.0.0 <4.0.0' | ||
|
||
dev_dependencies: | ||
lints: ^2.0.1 | ||
cider: ^0.2.3 | ||
test: ^1.21.1 | ||
check_coverage: ^0.0.2 | ||
|
||
cider: | ||
link_template: | ||
tag: 'https://github.com/f3ath/dart-quoted-string/releases/tag/%tag%' | ||
diff: 'https://github.com/f3ath/dart-quoted-string/compare/%from%...%to%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:quoted_string/quoted_string.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('Quoting', () { | ||
const cases = { | ||
r'"hello"\world ': r'"\"hello\"\\world "', | ||
r'': r'""', | ||
r'"': r'"\""', | ||
r'\': r'"\\"', | ||
}; | ||
cases.forEach((unquoted, quoted) { | ||
test('<$unquoted> => <$quoted>', () { | ||
expect(unquoted.quote(), equals(quoted)); | ||
}); | ||
}); | ||
}); | ||
|
||
group('Unquoting', () { | ||
const cases = { | ||
'': '', | ||
'foo': 'foo', | ||
'"': '"', | ||
'""': '', | ||
r'"\\"': r'\', | ||
r'"\"': r'"\"', | ||
r'"\\\"': r'"\\\"', | ||
r'"\\\""': r'\"', | ||
}; | ||
cases.forEach((quoted, unquoted) { | ||
test('<$quoted> => <$unquoted>', () { | ||
expect(quoted.unquote(), equals(unquoted)); | ||
}); | ||
}); | ||
}); | ||
} |