Difference between revisions of "SDF"
(SDF format description) |
m |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | + | {{SDF}} | |
− | SDF | ||
− | |||
− | + | '''SDF''' is a delimited text file format used in Delphi (and later FreePascal) that is very much like, but not the same, as [[CSV]]. | |
− | A summary of the SDF format as used in TStringList, as paraphrased/synthesized from various versions of Delphi help (e.g. [http://docwiki.embarcadero.com/Libraries/en/System.Classes.TStrings.DelimitedText DelimitedText], [http://docwiki.embarcadero.com/Libraries/en/System.Classes.TStrings.StrictDelimiter StrictDelimiter]) | + | (<tt>.sdf</tt> is also the extension of Microsoft SQL Server data files, therefore it may not be a good idea to use the <tt>.sdf</tt> extension for your files). |
+ | |||
+ | == SDF format == | ||
+ | A summary of the SDF format as used in [[TStringList]], as paraphrased/synthesized from various versions of Delphi help (e.g. [http://docwiki.embarcadero.com/Libraries/en/System.Classes.TStrings.DelimitedText DelimitedText], [http://docwiki.embarcadero.com/Libraries/en/System.Classes.TStrings.StrictDelimiter StrictDelimiter]) | ||
* If you get DelimitedText, strings that include spaces, Delimiter (e.g. ,) or QuoteChar '''must''' be enclosed in QuoteChars (" by default) aka quoted. (In practice - read Delphi does this -, however, with StrictDelimiter on, e.g. spaced text is not quoted) | * If you get DelimitedText, strings that include spaces, Delimiter (e.g. ,) or QuoteChar '''must''' be enclosed in QuoteChars (" by default) aka quoted. (In practice - read Delphi does this -, however, with StrictDelimiter on, e.g. spaced text is not quoted) | ||
* In addition, a QuoteChar in a string '''must''' be repeated. | * In addition, a QuoteChar in a string '''must''' be repeated. | ||
* When setting DelimitedText, strings '''must''' be separated by Delimiter characters '''or''' spaces. | * When setting DelimitedText, strings '''must''' be separated by Delimiter characters '''or''' spaces. | ||
− | * Strings ''may'' be enclosed in QuoteChars. | + | * Strings '''may''' be enclosed in QuoteChars. |
* QuoteChars in the string '''must''' be repeated to distinguish them from the QuoteChars enclosing the string. | * QuoteChars in the string '''must''' be repeated to distinguish them from the QuoteChars enclosing the string. | ||
− | * Delimiters that are not contained within QuoteChar marks '''must'' be handled as delimiters | + | * Delimiters that are not contained within QuoteChar marks '''must''' be handled as delimiters |
* If StrictDelimiter is false, spaces that are not contained within QuoteChar marks '''must'' be handled as delimiters. | * If StrictDelimiter is false, spaces that are not contained within QuoteChar marks '''must'' be handled as delimiters. | ||
* Two Delimiters in a row indicate an empty string. | * Two Delimiters in a row indicate an empty string. | ||
− | |||
− | |||
== Example output == | == Example output == | ||
Example SDF output (tested in Delphi and FPC after applying the patch for issue 19610): | Example SDF output (tested in Delphi and FPC after applying the patch for issue 19610): | ||
− | + | {{Note|FPC versions below 2.6.0 do not generate SDF according to the specification}} | |
This series of strings in a stringlist (note: numbers in front indicate the field for clarity, they are not part of the data): | This series of strings in a stringlist (note: numbers in front indicate the field for clarity, they are not part of the data): | ||
Line 42: | Line 41: | ||
line.";" SpacesInFront";"SpacesAtTheEnd " | line.";" SpacesInFront";"SpacesAtTheEnd " | ||
− | [[ | + | == See also == |
+ | * [[CSV]] A related format | ||
+ | * [http://bugs.freepascal.org/view.php?id=19610 a patch that improved SDF input/output] | ||
+ | * [[TSdfDataSet]] |
Latest revision as of 13:46, 14 June 2017
│
English (en) │
français (fr) │
SDF is a delimited text file format used in Delphi (and later FreePascal) that is very much like, but not the same, as CSV. (.sdf is also the extension of Microsoft SQL Server data files, therefore it may not be a good idea to use the .sdf extension for your files).
SDF format
A summary of the SDF format as used in TStringList, as paraphrased/synthesized from various versions of Delphi help (e.g. DelimitedText, StrictDelimiter)
- If you get DelimitedText, strings that include spaces, Delimiter (e.g. ,) or QuoteChar must be enclosed in QuoteChars (" by default) aka quoted. (In practice - read Delphi does this -, however, with StrictDelimiter on, e.g. spaced text is not quoted)
- In addition, a QuoteChar in a string must be repeated.
- When setting DelimitedText, strings must be separated by Delimiter characters or spaces.
- Strings may be enclosed in QuoteChars.
- QuoteChars in the string must be repeated to distinguish them from the QuoteChars enclosing the string.
- Delimiters that are not contained within QuoteChar marks must be handled as delimiters
- If StrictDelimiter is false, spaces that are not contained within QuoteChar marks 'must be handled as delimiters.
- Two Delimiters in a row indicate an empty string.
Example output
Example SDF output (tested in Delphi and FPC after applying the patch for issue 19610):
This series of strings in a stringlist (note: numbers in front indicate the field for clarity, they are not part of the data):
0normal_string 1includes;delimiter 2includes space 3includes"quote 4includes "quote and space 5tab character 6"single_starting_quote 7multi line. 8 SpacesInFront 9SpacesAtTheEnd
gets output as this with StrictDelimiter true (and ; as delimiter):
normal_string;"includes;delimiter";includes space;"includes""quote";"includes ""quote and space";tab character;"""single_starting_quote";multi line.; SpacesInFront;SpacesAtTheEnd
... and output as this with StrictDelimiter false:
normal_string;"includes;delimiter";"includes space";"includes""quote";"includes ""quote and space";"tab character";"""single_starting_quote";"multi line.";" SpacesInFront";"SpacesAtTheEnd "
See also
- CSV A related format
- a patch that improved SDF input/output
- TSdfDataSet