// CreateStringSettings
using Leguar.TotalJSON.Internal;
namespace Leguar.TotalJSON {
///
/// Settings that can be used to make output of creating JSON-formatted string different.
///
public class CreateStringSettings {
private bool escapeForwardSlashes = false;
///
/// Sets forward slashes to escaped or not. TotalJSON default is false since escaped forward slashes could cause problems if included to C# code.
/// However, if resulting JSON string is included to for example HTML or JavaScript, it is better to set forward slash escaping on.
///
///
/// True to escape forward slashes ("\/"), false to not ("/").
///
public bool EscapeForwardSlashes {
set {
escapeForwardSlashes = value;
}
get {
return escapeForwardSlashes;
}
}
private bool humanReadable = false;
///
/// Sets output to be more human readable. Linefeeds and indentations are added to output to make it easier for humans to read and edit.
/// Output is still completely valid JSON that can be parsed back to JSON or JArray object.
///
///
/// True to make output human readable. Default is false.
///
public bool HumanReadable {
set {
humanReadable = value;
}
get {
return humanReadable;
}
}
private bool indentUsingTab = true;
///
/// Sets whatever indent of human readable output should use tabs. If false, spaces are used instead of tab.
///
///
/// This setting have effect only if 'HumanReadable' is true.
///
///
/// True to use tabs for indent. Default is true.
///
public bool IndentUsingTab {
set {
if (!humanReadable) {
DebugLogger.LogUserWarning("CreateStringSettings.IndentUsingTab setting have no effect when CreateStringSettings.HumanReadable is false");
}
indentUsingTab = value;
}
get {
return indentUsingTab;
}
}
private int indentSpaceCount = 4;
///
/// Sets how many spaces are used for indent. Can be 0 or any positive integer.
///
///
/// This setting have effect only if 'HumanReadable' is true and 'IndentUsingTab' is false.
///
///
/// Amount of spaces to use for indent. Default is 4.
///
public int IndentSpaceCount {
set {
if (!humanReadable) {
DebugLogger.LogUserWarning("CreateStringSettings.IndentSpaceCount setting have no effect when CreateStringSettings.HumanReadable is false");
} else if (indentUsingTab) {
DebugLogger.LogUserWarning("CreateStringSettings.IndentSpaceCount setting have no effect when CreateStringSettings.IndentUsingTab is true");
}
indentSpaceCount = value;
}
get {
return indentSpaceCount;
}
}
public enum NewLineTypes {
EnvironmentDefault,
LF,
CR_LF
}
private NewLineTypes newLine = NewLineTypes.EnvironmentDefault;
///
/// Sets type of linefeeds in human readable output.
///
///
/// This setting have effect only if 'HumanReadable' is true.
///
///
/// Type of linefeeds, one of values from NewLineTypes. Default is EnvironmentDefault.
///
public NewLineTypes NewLine {
set {
if (!humanReadable) {
DebugLogger.LogUserWarning("CreateStringSettings.NewLine setting have no effect when CreateStringSettings.HumanReadable is false");
}
newLine = value;
}
get {
return newLine;
}
}
private bool coloredOutput = false;
///
/// Sets output to be colored, using HTML style rich text tags.
///
///
/// If this setting is used, resulting string can NOT be parsed back to JSON object!
///
///
/// True to have color tags in output. Default is false.
///
public bool ColoredOutput {
set {
coloredOutput = value;
}
get {
return coloredOutput;
}
}
}
}