本文整理汇总了C#中ByteString.StartsWithIgnoreCase方法的典型用法代码示例。如果您正苦于以下问题:C# ByteString.StartsWithIgnoreCase方法的具体用法?C# ByteString.StartsWithIgnoreCase怎么用?C# ByteString.StartsWithIgnoreCase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ByteString
的用法示例。
在下文中一共展示了ByteString.StartsWithIgnoreCase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromUri
private static ImapSearchCriteria FromUri(Uri uri,
bool convertLiteral,
bool synchronizedLiteral,
bool splitCharset,
out bool containsLiteral,
out string charset)
{
if (uri == null)
throw new ArgumentNullException("uri");
containsLiteral = false;
charset = null;
var q = uri.Query;
if (q.Length == 0)
return null;
else if (q.Length == 1) // '?'
return new ImapSearchCriteria(string.Empty);
/*
* http://tools.ietf.org/html/rfc5092
* RFC 5092 - IMAP URL Scheme
*
* Note that quoted strings and non-synchronizing literals [LITERAL+]
* are allowed in the <enc-search> content; however, synchronizing
* literals are not allowed, as their presence would effectively mean
* that the agent interpreting IMAP URLs needs to parse an <enc-search>
* content, find all synchronizing literals, and perform proper command
* continuation request handling (see Sections 4.3 and 7 of [IMAP4]).
*/
var query = PercentEncoding.Decode(q.Substring(1), false);
var len = query.Length;
var convertedQuery = new ByteStringBuilder(len);
if (splitCharset) {
var queryString = new ByteString(query);
if (queryString.StartsWithIgnoreCase(charsetSpecification)) {
// CHARSET<SP>astring<SP>
var posEndOfCharset = queryString.IndexOf(Octets.SP, charsetSpecification.Length);
if (posEndOfCharset < 0) {
throw new ArgumentException("search criteria contains invalid charset specification", "uri");
}
else {
charset = queryString.Substring(charsetSpecification.Length,
posEndOfCharset - charsetSpecification.Length).ToString();
query = queryString.Substring(posEndOfCharset + 1).ByteArray;
len = query.Length;
}
}
}
for (var i = 0; i < len;) {
if (query[i] == ImapOctets.DQuote) {
/*
* quoted
*/
var start = i;
for (;;) {
if (++i == len)
throw new ArgumentException("search criteria contains unclosed quoted string", "uri");
if (query[i] == ImapOctets.DQuote) {
break;
}
else if (query[i] == ImapOctets.BackSlash) {
if (++i == len || !(query[i] == ImapOctets.DQuote || query[i] == ImapOctets.BackSlash))
throw new ArgumentException("search criteria contains invalid quoted string", "uri");
}
}
i++;
convertedQuery.Append(query, start, i - start);
}
else if (query[i] == ImapOctets.OpenBrace) {
/*
* literal
*/
var start = i;
var isLiteralSynchronizing = false;
var literalLength = 0;
for (;;) {
if (++i == len)
throw new ArgumentException("search criteria contains incomplete literal", "uri");
if (Octets.IsDecimalNumber(query[i])) {
literalLength = literalLength * 10 + (query[i] - 0x30 /* '0' */);
// TODO: check length
}
else if (query[i] == ImapOctets.CloseBrace) {
// {xxx}
isLiteralSynchronizing = true;
break;
}
//.........这里部分代码省略.........
示例2: TestStartsWithIgnoreCase
public void TestStartsWithIgnoreCase()
{
var str = new ByteString("aBC");
Assert.IsTrue(str.StartsWithIgnoreCase(new ByteString("abc")));
Assert.IsTrue(str.StartsWithIgnoreCase(new ByteString("aBc")));
Assert.IsTrue(str.StartsWithIgnoreCase(new ByteString("aBC")));
Assert.IsTrue(str.StartsWithIgnoreCase(new ByteString("ABc")));
Assert.IsTrue(str.StartsWithIgnoreCase(new ByteString("AbC")));
Assert.IsFalse(str.StartsWithIgnoreCase(new ByteString("abd")));
Assert.IsFalse(str.StartsWithIgnoreCase(new ByteString("abcdef")));
}