-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DefaultWktOutputFormatter now working
Also reparsing in unit test ParseAllWKTs from SRID csv => Works!
- Loading branch information
Showing
21 changed files
with
910 additions
and
13 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,198 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Text; | ||
|
||
namespace ProjNet.Wkt | ||
{ | ||
/// <summary> | ||
/// DefaultWktOutputFormatter - Keeping output compact with original delimiters. | ||
/// </summary> | ||
public class DefaultWktOutputFormatter : IWktOutputFormatter | ||
{ | ||
private int indentCounter = 0; | ||
|
||
/// <inheritdoc/> | ||
public string Newline { get; } = null; | ||
/// <inheritdoc/> | ||
public char? LeftDelimiter { get; } = null; | ||
/// <inheritdoc/> | ||
public char? RightDelimiter { get; } = null; | ||
|
||
/// <inheritdoc/> | ||
public string Separator { get; } = null; | ||
|
||
/// <summary> | ||
/// Indent chars. E.g. tab or spaces. Default null. | ||
/// </summary> | ||
public string Indent { get; } = null; | ||
|
||
/// <inheritdoc/> | ||
public string ExtraWhitespace { get; } = null; | ||
|
||
|
||
/// <summary> | ||
/// Constructor with support for optional overriding the settings. | ||
/// </summary> | ||
/// <param name="newline"></param> | ||
/// <param name="leftDelimiter"></param> | ||
/// <param name="rightDelimiter"></param> | ||
/// <param name="indent"></param> | ||
/// <param name="extraWhitespace"></param> | ||
public DefaultWktOutputFormatter( | ||
string newline = null, | ||
char? leftDelimiter = null, | ||
char? rightDelimiter = null, | ||
string indent = null, | ||
string extraWhitespace = null) | ||
{ | ||
Newline = newline; | ||
LeftDelimiter = leftDelimiter; | ||
RightDelimiter = rightDelimiter; | ||
Indent = indent; | ||
ExtraWhitespace = extraWhitespace; | ||
} | ||
|
||
|
||
/// <inheritdoc/> | ||
public IWktOutputFormatter AppendKeyword(string text, StringBuilder result, bool indent = true) | ||
{ | ||
if (indent) | ||
this.AppendIndent(result); | ||
|
||
result.Append(text); | ||
|
||
this.IncreaseIndentCounter(); | ||
|
||
return this; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IWktOutputFormatter AppendSeparator(StringBuilder result, bool keepInside = false) | ||
{ | ||
string s = Separator ?? ","; | ||
result.Append(s); | ||
if (!keepInside) | ||
{ | ||
this.AppendNewline(result); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
|
||
/// <inheritdoc/> | ||
public IWktOutputFormatter Append(string text, StringBuilder result) | ||
{ | ||
result.Append(text); | ||
return this; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IWktOutputFormatter Append(long l, StringBuilder result) | ||
{ | ||
result.Append(l); | ||
return this; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IWktOutputFormatter Append(double d, StringBuilder result) | ||
{ | ||
result.Append(d.ToString(CultureInfo.InvariantCulture)); | ||
return this; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IWktOutputFormatter AppendNewline(StringBuilder result) | ||
{ | ||
if (!string.IsNullOrEmpty(Newline)) | ||
{ | ||
result.Append(Newline); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IWktOutputFormatter AppendQuotedText(string text, StringBuilder result) | ||
{ | ||
result.Append($"\"{text}\""); | ||
return this; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IWktOutputFormatter AppendLeftDelimiter(char original, StringBuilder result) | ||
{ | ||
if (LeftDelimiter != null) | ||
result.Append(LeftDelimiter); | ||
else | ||
result.Append(original); | ||
return this; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IWktOutputFormatter AppendRightDelimiter(char original, StringBuilder result) | ||
{ | ||
//this.AppendIndent(result); | ||
|
||
if (RightDelimiter != null) | ||
result.Append(RightDelimiter); | ||
else | ||
result.Append(original); | ||
|
||
this.DecreaseIndentCounter(); | ||
//this.AppendNewline(result); | ||
|
||
return this; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IWktOutputFormatter AppendExtraWhitespace(StringBuilder result) | ||
{ | ||
if (!string.IsNullOrEmpty(ExtraWhitespace)) | ||
{ | ||
result.Append(ExtraWhitespace); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Increasing the indentCounter. | ||
/// </summary> | ||
/// <returns></returns> | ||
public IWktOutputFormatter IncreaseIndentCounter() | ||
{ | ||
indentCounter++; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Decreasing the indentCounter. | ||
/// </summary> | ||
/// <returns></returns> | ||
public IWktOutputFormatter DecreaseIndentCounter() | ||
{ | ||
indentCounter--; | ||
return this; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// AppendIndent repeat Indent according to internal indentCounter. | ||
/// </summary> | ||
/// <param name="result"></param> | ||
/// <returns></returns> | ||
public IWktOutputFormatter AppendIndent(StringBuilder result) | ||
{ | ||
if (!string.IsNullOrEmpty(Indent)) | ||
{ | ||
for (int i = 1; i <= indentCounter; i++) | ||
{ | ||
result.Append(Indent); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
} | ||
} |
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,139 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace ProjNet.Wkt | ||
{ | ||
|
||
/// <summary> | ||
/// IWktOutputFormatter interface for customizing ToString(...) support. | ||
/// </summary> | ||
public interface IWktOutputFormatter | ||
{ | ||
/// <summary> | ||
/// Newline char or empty string. Default empty. | ||
/// </summary> | ||
string Newline { get; } | ||
|
||
/// <summary> | ||
/// LeftDelimiter if empty use original. Default empty. | ||
/// </summary> | ||
char? LeftDelimiter { get; } | ||
/// <summary> | ||
/// RightDelimiter if empty use original. Default empty. | ||
/// </summary> | ||
char? RightDelimiter { get; } | ||
|
||
/// <summary> | ||
/// Separator to use. Default comma , | ||
/// </summary> | ||
string Separator { get; } | ||
|
||
/// <summary> | ||
/// ExtraWhitespace. Default empty. | ||
/// </summary> | ||
string ExtraWhitespace { get; } | ||
|
||
|
||
/// <summary> | ||
/// Changeable Append method for Keywords. Optional extra indent is written. | ||
/// </summary> | ||
/// <param name="text"></param> | ||
/// <param name="result"></param> | ||
/// <param name="indent"></param> | ||
/// <returns></returns> | ||
IWktOutputFormatter AppendKeyword(string text, StringBuilder result, bool indent = true); | ||
|
||
|
||
/// <summary> | ||
/// Changeable Append method for Separator. Optional extra newline afterward. | ||
/// </summary> | ||
/// <param name="result"></param> | ||
/// <param name="keepInside"></param> | ||
/// <returns></returns> | ||
IWktOutputFormatter AppendSeparator(StringBuilder result, bool keepInside = false); | ||
|
||
/// <summary> | ||
/// Changeable Append method for string. | ||
/// </summary> | ||
/// <param name="text"></param> | ||
/// <param name="result"></param> | ||
/// <returns></returns> | ||
IWktOutputFormatter Append(string text, StringBuilder result); | ||
|
||
/// <summary> | ||
/// Changeable Append method for long. | ||
/// </summary> | ||
/// <param name="l"></param> | ||
/// <param name="result"></param> | ||
/// <returns></returns> | ||
IWktOutputFormatter Append(long l, StringBuilder result); | ||
|
||
/// <summary> | ||
/// Changeable Append method for double. | ||
/// </summary> | ||
/// <param name="d"></param> | ||
/// <param name="result"></param> | ||
/// <returns></returns> | ||
IWktOutputFormatter Append(double d, StringBuilder result); | ||
|
||
|
||
/// <summary> | ||
/// Changeable AppendNewline method applying Newline. | ||
/// </summary> | ||
/// <param name="result"></param> | ||
/// <returns></returns> | ||
IWktOutputFormatter AppendNewline(StringBuilder result); | ||
|
||
/// <summary> | ||
/// Changeable AppendQuotedText method applying text surrounded by double quotes. | ||
/// </summary> | ||
/// <param name="text"></param> | ||
/// <param name="result"></param> | ||
/// <returns></returns> | ||
IWktOutputFormatter AppendQuotedText(string text, StringBuilder result); | ||
|
||
/// <summary> | ||
/// Changeable AppendLeftDelimiter applying LeftDelimiter or original. | ||
/// </summary> | ||
/// <param name="original"></param> | ||
/// <param name="result"></param> | ||
/// <returns></returns> | ||
IWktOutputFormatter AppendLeftDelimiter(char original, StringBuilder result); | ||
|
||
/// <summary> | ||
/// Changeable AppendRightDelimiter applying RightDelimiter or original. | ||
/// </summary> | ||
/// <param name="original"></param> | ||
/// <param name="result"></param> | ||
/// <returns></returns> | ||
IWktOutputFormatter AppendRightDelimiter(char original, StringBuilder result); | ||
|
||
|
||
/// <summary> | ||
/// Changeable AppendExtraWhitespace optionally applying extr whitespace. | ||
/// </summary> | ||
/// <param name="result"></param> | ||
/// <returns></returns> | ||
IWktOutputFormatter AppendExtraWhitespace(StringBuilder result); | ||
|
||
/// <summary> | ||
/// IncreaseIndentCounter | ||
/// </summary> | ||
/// <returns></returns> | ||
IWktOutputFormatter IncreaseIndentCounter(); | ||
|
||
/// <summary> | ||
/// DecreaseIndentCounter | ||
/// </summary> | ||
/// <returns></returns> | ||
IWktOutputFormatter DecreaseIndentCounter(); | ||
|
||
|
||
/// <summary> | ||
/// AppendIndent | ||
/// </summary> | ||
/// <param name="result"></param> | ||
/// <returns></returns> | ||
IWktOutputFormatter AppendIndent(StringBuilder result); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/ProjNet/Wkt/Tree/IWktTraverseHandler.cs → src/ProjNet/Wkt/IWktTraverseHandler.cs
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
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
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
Oops, something went wrong.