NanoXLSX.Core 3.2.1
Loading...
Searching...
No Matches
NanoXLSX.Utils.ParserUtils Class Reference

Class providing static methods to parse string values to specific types or to print object as language neutral string. More...

Static Public Member Functions

static bool StartsWith (string input, string value)
 Determines whether a string starts with a specific value.
static bool NotStartsWith (string input, string value)
 Determines whether a string does not start with a specific value.
static string ToUpper (string input)
 Transforms a string to upper case with null check and invariant culture.
static string ToLower (string input)
 Transforms a string to lower case with null check and invariant culture.
static string ToString (int input)
 Transforms an integer to an invariant sting.
static string ToString (float input)
 Transforms a float to an invariant sting.
static string ToString (byte input)
 Transforms a byte to an invariant sting.
static string ToString (sbyte input)
 Transforms a sbyte to an invariant sting.
static string ToString (double input)
 Transforms a double to an invariant sting.
static string ToString (decimal input)
 Transforms a decimal to an invariant sting.
static string ToString (uint input)
 Transforms a uint to an invariant sting.
static string ToString (long input)
 Transforms a long to an invariant sting.
static string ToString (ulong input)
 Transforms a ulong to an invariant sting.
static string ToString (short input)
 Transforms a short to an invariant sting.
static string ToString (ushort input)
 Transforms a ushort to an invariant sting.
static float ParseFloat (string rawValue)
 Parses a float independent from the culture info of the host.
static int ParseInt (string rawValue)
 Parses an int independent from the culture info of the host.
static double ParseDouble (string rawValue)
 Parses a double independent from the culture info of the host.
static int ParseBinaryBool (String rawValue)
 Parses a bool as a binary number either based on an int (0/1) or a string expression (true/ false), independent of the culture info of the host.
static bool TryParseBool (string rawValue, out bool parsedValue)
 Tries to parse a bool from its string name (true/false), independent from the case.
static bool TryParseInt (string rawValue, out int parsedValue)
 Tries to parse an int independent of the culture info of the host.
static bool TryParseUint (string rawValue, out uint parsedValue)
 Tries to parse an unsigned int (uint) independent from the culture info of the host.
static bool TryParseLong (string rawValue, out long parsedValue)
 Tries to parse a long independent from the culture info of the host.
static bool TryParseUlong (string rawValue, out ulong parsedValue)
 Tries to parse an unsigned long (ulong) independent from the culture info of the host.
static bool TryParseFloat (string rawValue, out float parsedValue)
 Tries to parse a float (with any parsing style) independent from the culture info of the host.
static bool TryParseDecimal (string rawValue, out decimal parsedValue)
 Tries to parse a decimal (with float parsing style) independent from the culture info of the host.
static bool TryParseDouble (string rawValue, out double parsedValue, NumberStyles numberStyles=NumberStyles.Any)
 Tries to parse a double independent from the culture info of the host.
static string NormalizeNewLines (string value)
 Normalizes all newlines of a string to CR+LF.
static bool IsAsciiDigit (char character)
 Determines whether the passed character is a ASCII digit character (0-9).
static string ToCachedValueString (object input, bool convertBoolToNumber=true)
 Transforms a given object to a string displayed as cached Values. The common known compatible numeric types, like int, float, sbyte etc. will be transformed to their appropriate string representations.
Bool will be either 0 or 1, or to TRUE or FALSE if convertBoolToNumber is set to false. Date or TimeSpan will be transformed to a OADate (numeric) value. Null or an empty string will be transformed to 0. If an unknown object type is passed, its own ToString() method will be used.
static bool TryParseFormulaStringConstant (string expression, out string value, bool enclosingQuotesRemoved=false)
 Tries to parse a raw string as an Excel formula string constant. Escaped double quotes ("") are converted to single double quotes (").
static bool TryParseWorksheetQualifiedReference (string expression, out string worksheetName, out string reference)
 Tries to parse a qualifies worksheet name and address or range expression from a raw string.

Static Public Attributes

const string NumericFormat = "G"
 Numeric format for ToString conversions. This format ensures that a numeric value is printed in a language neutral way.
static readonly CultureInfo InvariantCulture = CultureInfo.InvariantCulture
 Constant for number conversion. The invariant culture (represents mostly the US numbering scheme) ensures that no culture-specific punctuations are used when converting numbers to strings, This is especially important for OOXML number values. See also: https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.invariantculture?view=net-5.0.

Detailed Description

Class providing static methods to parse string values to specific types or to print object as language neutral string.

Remarks
Methods in this class should only be used by the library components and not called by user code

Definition at line 19 of file ParserUtils.cs.

Member Function Documentation

◆ IsAsciiDigit()

bool NanoXLSX.Utils.ParserUtils.IsAsciiDigit ( char character)
static

Determines whether the passed character is a ASCII digit character (0-9).

Parameters
characterCharacter to check
Returns
True if an ASCII character, otherwise false

Definition at line 369 of file ParserUtils.cs.

◆ NormalizeNewLines()

string NanoXLSX.Utils.ParserUtils.NormalizeNewLines ( string value)
static

Normalizes all newlines of a string to CR+LF.

Parameters
valueInput value
Returns
Normalized value

Definition at line 355 of file ParserUtils.cs.

◆ NotStartsWith()

bool NanoXLSX.Utils.ParserUtils.NotStartsWith ( string input,
string value )
static

Determines whether a string does not start with a specific value.

Parameters
inputString to check
valueValue to be checked, whether it occurs not at the beginning of the input string
Returns
True if the input string does not starts with the specified value

Definition at line 68 of file ParserUtils.cs.

◆ ParseBinaryBool()

int NanoXLSX.Utils.ParserUtils.ParseBinaryBool ( String rawValue)
static

Parses a bool as a binary number either based on an int (0/1) or a string expression (true/ false), independent of the culture info of the host.

Parameters
rawValueRaw number or expression as string
Returns
Parsed bool as number (0 = false, 1 = true)

Definition at line 241 of file ParserUtils.cs.

◆ ParseDouble()

double NanoXLSX.Utils.ParserUtils.ParseDouble ( string rawValue)
static

Parses a double independent from the culture info of the host.

Parameters
rawValueRaw number as string
Returns
Parsed int
Remarks
The method does not check the validity and will cause an error if an invalid value is passed

Definition at line 231 of file ParserUtils.cs.

◆ ParseFloat()

float NanoXLSX.Utils.ParserUtils.ParseFloat ( string rawValue)
static

Parses a float independent from the culture info of the host.

Parameters
rawValueRaw number as string
Returns
Parsed float
Remarks
The method does not check the validity and will cause an error if an invalid value is passed

Definition at line 209 of file ParserUtils.cs.

◆ ParseInt()

int NanoXLSX.Utils.ParserUtils.ParseInt ( string rawValue)
static

Parses an int independent from the culture info of the host.

Parameters
rawValueRaw number as string
Returns
Parsed int
Remarks
The method does not check the validity and will cause an error if an invalid value is passed

Definition at line 220 of file ParserUtils.cs.

◆ StartsWith()

bool NanoXLSX.Utils.ParserUtils.StartsWith ( string input,
string value )
static

Determines whether a string starts with a specific value.

Parameters
inputString to check
valueValue to be checked, whether it occurs at the beginning of the input string
Returns
True if the input string starts with the specified value

Definition at line 45 of file ParserUtils.cs.

◆ ToCachedValueString()

string NanoXLSX.Utils.ParserUtils.ToCachedValueString ( object input,
bool convertBoolToNumber = true )
static

Transforms a given object to a string displayed as cached Values. The common known compatible numeric types, like int, float, sbyte etc. will be transformed to their appropriate string representations.
Bool will be either 0 or 1, or to TRUE or FALSE if convertBoolToNumber is set to false. Date or TimeSpan will be transformed to a OADate (numeric) value. Null or an empty string will be transformed to 0. If an unknown object type is passed, its own ToString() method will be used.

Parameters
inputObject to transform
convertBoolToNumberIf set to true, a bool value will be 1 or 0, otherwise TRUE or FALSE. Default is true
Returns
Most appropriate OOXML string form given
Exceptions
Exceptions.FormatExceptionThrown if an invalid Date value was passed. See method DataUtils.GetOADateTimeString(DateTime) for details
Remarks
This method transforms values to the Excel-internal OOXML format. It is not meant as a generic ToString() method. Also do not pass nested objects like Cell or FormulaData, since they will be handled as unknown object types.

Definition at line 388 of file ParserUtils.cs.

◆ ToLower()

string NanoXLSX.Utils.ParserUtils.ToLower ( string input)
static

Transforms a string to lower case with null check and invariant culture.

Parameters
inputString to transform
Returns
Lower case string

Definition at line 88 of file ParserUtils.cs.

◆ ToString() [1/11]

string NanoXLSX.Utils.ParserUtils.ToString ( byte input)
static

Transforms a byte to an invariant sting.

Parameters
inputByte to transform
Returns
Byte as string

Definition at line 118 of file ParserUtils.cs.

◆ ToString() [2/11]

string NanoXLSX.Utils.ParserUtils.ToString ( decimal input)
static

Transforms a decimal to an invariant sting.

Parameters
inputDecimal to transform
Returns
Decimal as string

Definition at line 148 of file ParserUtils.cs.

◆ ToString() [3/11]

string NanoXLSX.Utils.ParserUtils.ToString ( double input)
static

Transforms a double to an invariant sting.

Parameters
inputDouble to transform
Returns
Double as string

Definition at line 138 of file ParserUtils.cs.

◆ ToString() [4/11]

string NanoXLSX.Utils.ParserUtils.ToString ( float input)
static

Transforms a float to an invariant sting.

Parameters
inputFloat to transform
Returns
Float as string

Definition at line 108 of file ParserUtils.cs.

◆ ToString() [5/11]

string NanoXLSX.Utils.ParserUtils.ToString ( int input)
static

Transforms an integer to an invariant sting.

Parameters
inputInteger to transform
Returns
Integer as string

Definition at line 98 of file ParserUtils.cs.

◆ ToString() [6/11]

string NanoXLSX.Utils.ParserUtils.ToString ( long input)
static

Transforms a long to an invariant sting.

Parameters
inputLong to transform
Returns
Long as string

Definition at line 168 of file ParserUtils.cs.

◆ ToString() [7/11]

string NanoXLSX.Utils.ParserUtils.ToString ( sbyte input)
static

Transforms a sbyte to an invariant sting.

Parameters
inputSbyte to transform
Returns
Byte as string

Definition at line 128 of file ParserUtils.cs.

◆ ToString() [8/11]

string NanoXLSX.Utils.ParserUtils.ToString ( short input)
static

Transforms a short to an invariant sting.

Parameters
inputShort to transform
Returns
Short as string

Definition at line 188 of file ParserUtils.cs.

◆ ToString() [9/11]

string NanoXLSX.Utils.ParserUtils.ToString ( uint input)
static

Transforms a uint to an invariant sting.

Parameters
inputUint to transform
Returns
Uint as string

Definition at line 158 of file ParserUtils.cs.

◆ ToString() [10/11]

string NanoXLSX.Utils.ParserUtils.ToString ( ulong input)
static

Transforms a ulong to an invariant sting.

Parameters
inputUlong to transform
Returns
Ulong as string

Definition at line 178 of file ParserUtils.cs.

◆ ToString() [11/11]

string NanoXLSX.Utils.ParserUtils.ToString ( ushort input)
static

Transforms a ushort to an invariant sting.

Parameters
inputUshort to transform
Returns
Ushort as string

Definition at line 198 of file ParserUtils.cs.

◆ ToUpper()

string NanoXLSX.Utils.ParserUtils.ToUpper ( string input)
static

Transforms a string to upper case with null check and invariant culture.

Parameters
inputString to transform
Returns
Upper case string

Definition at line 78 of file ParserUtils.cs.

◆ TryParseBool()

bool NanoXLSX.Utils.ParserUtils.TryParseBool ( string rawValue,
out bool parsedValue )
static

Tries to parse a bool from its string name (true/false), independent from the case.

Parameters
rawValueRaw bool as string
parsedValueParsed bool
Returns
True, if the parsing was successful

/remark

Integer values, like 0 or 1 will return false

Definition at line 267 of file ParserUtils.cs.

◆ TryParseDecimal()

bool NanoXLSX.Utils.ParserUtils.TryParseDecimal ( string rawValue,
out decimal parsedValue )
static

Tries to parse a decimal (with float parsing style) independent from the culture info of the host.

Parameters
rawValueRaw number as string
parsedValueParsed decimal
Returns
True, if the parsing was successful

Definition at line 333 of file ParserUtils.cs.

◆ TryParseDouble()

bool NanoXLSX.Utils.ParserUtils.TryParseDouble ( string rawValue,
out double parsedValue,
NumberStyles numberStyles = NumberStyles::Any )
static

Tries to parse a double independent from the culture info of the host.

Parameters
rawValueRaw number as string
parsedValueParsed double
numberStylesPermitted number styles. Default is NumberStyles.Any
Returns
True, if the parsing was successful

Definition at line 345 of file ParserUtils.cs.

◆ TryParseFloat()

bool NanoXLSX.Utils.ParserUtils.TryParseFloat ( string rawValue,
out float parsedValue )
static

Tries to parse a float (with any parsing style) independent from the culture info of the host.

Parameters
rawValueRaw number as string
parsedValueParsed float
Returns
True, if the parsing was successful

Definition at line 322 of file ParserUtils.cs.

◆ TryParseFormulaStringConstant()

bool NanoXLSX.Utils.ParserUtils.TryParseFormulaStringConstant ( string expression,
out string value,
bool enclosingQuotesRemoved = false )
static

Tries to parse a raw string as an Excel formula string constant. Escaped double quotes ("") are converted to single double quotes (").

Parameters
expressionRaw string expression.
valueParsed and unescaped string value as out parameter.
enclosingQuotesRemovedIf true, the enclosing leading and trailing double quotes have already been removed. Default is false.
Returns
True if the expression is a valid formula string constant; otherwise false.

Definition at line 440 of file ParserUtils.cs.

◆ TryParseInt()

bool NanoXLSX.Utils.ParserUtils.TryParseInt ( string rawValue,
out int parsedValue )
static

Tries to parse an int independent of the culture info of the host.

Parameters
rawValueRaw number as string
parsedValueParsed int
Returns
True, if the parsing was successful

Definition at line 278 of file ParserUtils.cs.

◆ TryParseLong()

bool NanoXLSX.Utils.ParserUtils.TryParseLong ( string rawValue,
out long parsedValue )
static

Tries to parse a long independent from the culture info of the host.

Parameters
rawValueRaw number as string
parsedValueParsed long
Returns
True, if the parsing was successful

Definition at line 300 of file ParserUtils.cs.

◆ TryParseUint()

bool NanoXLSX.Utils.ParserUtils.TryParseUint ( string rawValue,
out uint parsedValue )
static

Tries to parse an unsigned int (uint) independent from the culture info of the host.

Parameters
rawValueRaw number as string
parsedValueParsed uint
Returns
True, if the parsing was successful

Definition at line 289 of file ParserUtils.cs.

◆ TryParseUlong()

bool NanoXLSX.Utils.ParserUtils.TryParseUlong ( string rawValue,
out ulong parsedValue )
static

Tries to parse an unsigned long (ulong) independent from the culture info of the host.

Parameters
rawValueRaw number as string
parsedValueParsed ulong
Returns
True, if the parsing was successful

Definition at line 311 of file ParserUtils.cs.

◆ TryParseWorksheetQualifiedReference()

bool NanoXLSX.Utils.ParserUtils.TryParseWorksheetQualifiedReference ( string expression,
out string worksheetName,
out string reference )
static

Tries to parse a qualifies worksheet name and address or range expression from a raw string.

Parameters
expressionRaw expression to parse
worksheetNameResolved worksheet name as out parameter
referenceResolved address or range expression as string (out parameter)
Returns
True if the expression is a valid worksheet name with attached reference (address / range); otherwise false.
Remarks
This method cannot detect worksheet names and references within formulas or cell calculations. Such an expression has to be tokenized first.

Definition at line 501 of file ParserUtils.cs.

Member Data Documentation

◆ InvariantCulture

readonly CultureInfo NanoXLSX.Utils.ParserUtils.InvariantCulture = CultureInfo.InvariantCulture
static

Constant for number conversion. The invariant culture (represents mostly the US numbering scheme) ensures that no culture-specific punctuations are used when converting numbers to strings, This is especially important for OOXML number values. See also: https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.invariantculture?view=net-5.0.

Definition at line 34 of file ParserUtils.cs.

◆ NumericFormat

const string NanoXLSX.Utils.ParserUtils.NumericFormat = "G"
static

Numeric format for ToString conversions. This format ensures that a numeric value is printed in a language neutral way.

Definition at line 26 of file ParserUtils.cs.


The documentation for this class was generated from the following file: