Skip to content

zy/47 fix multiline issue #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions example/example_7.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'dart:io';

import 'package:rdflib/rdflib.dart';

main() async {
String filePath = 'example/sample_ttl_6.ttl';
// Read file content to a local String.
String fileContents = await File(filePath).readAsStringSync();

print('-------Original file-------\n$fileContents');

// Create a graph to read turtle file and store info.
Graph g = Graph();

// Parse with the new method [Graph.parseTurtle] instead of [Graph.parse] (deprecated).
g.parseTurtle(fileContents);

// Serialize the Graph for output.
g.serialize(format: 'ttl', abbr: 'short');
print('-------Serialized String--------\n${g.serializedString}');

// Print out full format of triples (will use shorthand in serialization/export).
print('--------All triples in the graph-------');
for (Triple t in g.triples) {
print(t);
}
}
14 changes: 14 additions & 0 deletions example/sample_ttl_6.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix show: <http://example.org/vocab/show/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

show:218 rdfs:label "That Seventies Show"^^xsd:string .
show:218 rdfs:label "That Seventies Show"^^<http://www.w3.org/2001/XMLSchema#string> .
show:218 rdfs:label "That Seventies Show" .
show:218 show:localName "That Seventies Show"@en .
show:218 show:localName 'Cette Série des Années Soixante-dix'@fr .
show:218 show:localName "Cette Série des Années Septante"@fr-be .
show:218 show:blurb '''This is a multi-line
literal with many quotes (""""")
and up to two sequential apostrophes ('').'''^^xsd:string .

6 changes: 5 additions & 1 deletion lib/src/graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,9 @@ class Graph {
String _preprocessTurtleContent(String turtleContent) {
// Regular expression to match multiline literals.

final multilineLiteralRegex = RegExp(r'"""(.*?)"""', dotAll: true);
final multilineLiteralRegex = RegExp(
turtleContent.contains("'''") ? r"'''(.*?)'''" : r'"""(.*?)"""',
dotAll: true);

// Replace each multiline literal with a processed version.

Expand All @@ -1132,6 +1134,8 @@ class Graph {
// Example: Replace line breaks with a special sequence.
String processedLiteral = multilineLiteral.replaceAll('\n', '\\n');

processedLiteral = processedLiteral.replaceAll('"', '\\"');

// Return the processed literal with the original triple quotes
return '"$processedLiteral"';
});
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
http: ^1.2.2
logging: ^1.2.0
petitparser: ^6.0.2
uuid: ^4.4.2
uuid: ^4.4.1

dev_dependencies:
lints: ^2.0.1
Expand Down
Loading