-
-
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.
add CRLF encoding and configurable text clipping
- Loading branch information
1 parent
0fd4403
commit 8cd2da3
Showing
9 changed files
with
61 additions
and
27 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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
15 changes: 0 additions & 15 deletions
15
src/Goblinfactory.PrettyJson/Goblinfactory.PrettyJson/EncodingExtensions.cs
This file was deleted.
Oops, something went wrong.
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
28 changes: 28 additions & 0 deletions
28
src/Goblinfactory.PrettyJson/Goblinfactory.PrettyJson/StringExtensions.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Goblinfactory.PrettyJson.Internal | ||
{ | ||
internal static class StringExtensions | ||
{ | ||
// this does not do url encoding | ||
// further reading | ||
// https://coder.today/tech/2017-10-20_encoding-in-web-development.-why-how-url-json-base64-beyond/ | ||
// and https://www.ietf.org/rfc/rfc4627.txt | ||
public static string ToJsonEncode(this string src, IPrettyConfig config) | ||
{ | ||
return src | ||
.Replace(@"\", @"\\") | ||
.Replace("\"", "\\\"") | ||
.Replace("\n", "\\n") | ||
.Replace("\r", "\\r") | ||
.Clip(config.ClipStringMaxLen); | ||
} | ||
|
||
public static string Clip(this string src, int? maxLen) | ||
{ | ||
if (maxLen == null) return src; | ||
if (src == null) return null; | ||
if (src.Length <= maxLen) return src; | ||
if(maxLen<10) return src.Substring(0, maxLen.Value); | ||
return $"{src.Substring(0, maxLen.Value - 3)}..."; | ||
} | ||
} | ||
} |