mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-05-16 01:17:03 +02:00
SMBServer v1.0.5
This commit is contained in:
parent
b75820452d
commit
bd1006cb81
400 changed files with 28062 additions and 0 deletions
114
Utilities/Strings/QuotedStringUtils.cs
Normal file
114
Utilities/Strings/QuotedStringUtils.cs
Normal file
|
@ -0,0 +1,114 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
public class QuotedStringUtils
|
||||
{
|
||||
public static string Quote(string str)
|
||||
{
|
||||
return String.Format("\"{0}\"", str);
|
||||
}
|
||||
|
||||
public static string Unquote(string str)
|
||||
{
|
||||
string quote = '"'.ToString();
|
||||
if (str.Length >= 2 && str.StartsWith(quote) && str.EndsWith(quote))
|
||||
{
|
||||
return str.Substring(1, str.Length - 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsQuoted(string str)
|
||||
{
|
||||
string quote = '"'.ToString();
|
||||
if (str.Length >= 2 && str.StartsWith(quote) && str.EndsWith(quote))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static int IndexOfUnquotedChar(string str, char charToFind)
|
||||
{
|
||||
return IndexOfUnquotedChar(str, charToFind, 0);
|
||||
}
|
||||
|
||||
public static int IndexOfUnquotedChar(string str, char charToFind, int startIndex)
|
||||
{
|
||||
if (startIndex >= str.Length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool inQuote = false;
|
||||
int index = startIndex;
|
||||
while (index < str.Length)
|
||||
{
|
||||
if (str[index] == '"')
|
||||
{
|
||||
inQuote = !inQuote;
|
||||
}
|
||||
else if (!inQuote && str[index] == charToFind)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int IndexOfUnquotedString(string str, string stringToFind)
|
||||
{
|
||||
return IndexOfUnquotedString(str, stringToFind, 0);
|
||||
}
|
||||
|
||||
public static int IndexOfUnquotedString(string str, string stringToFind, int startIndex)
|
||||
{
|
||||
if (startIndex >= str.Length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool inQuote = false;
|
||||
int index = startIndex;
|
||||
while (index < str.Length)
|
||||
{
|
||||
if (str[index] == '"')
|
||||
{
|
||||
inQuote = !inQuote;
|
||||
}
|
||||
else if (!inQuote && str.Substring(index).StartsWith(stringToFind))
|
||||
{
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static List<string> SplitIgnoreQuotedSeparators(string str, char separator)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
int nextEntryIndex = 0;
|
||||
int separatorIndex = IndexOfUnquotedChar(str, separator);
|
||||
while (separatorIndex >= nextEntryIndex)
|
||||
{
|
||||
result.Add(str.Substring(nextEntryIndex, separatorIndex - nextEntryIndex));
|
||||
|
||||
nextEntryIndex = separatorIndex + 1;
|
||||
separatorIndex = IndexOfUnquotedChar(str, separator, nextEntryIndex);
|
||||
}
|
||||
result.Add(str.Substring(nextEntryIndex));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue