/// <summary> /// <para>Returns a byte array from a string representing a hexadecimal number.</para> /// </summary> /// <param name="hexadecimalNumber"> /// <para>The string containing a valid hexadecimal number.</para> /// </param> /// <returns><para>The byte array representing the hexadecimal.</para></returns> public static Byte[] GetBytesFromHexString(String hexadecimalNumber) { if (hexadecimalNumber == null) throw new ArgumentNullException("hexadecimalNumber"); var sb = new StringBuilder(hexadecimalNumber.ToUpperInvariant()); if (sb[0].Equals('0') && sb[1].Equals('X')) { sb.Remove(0, 2); } if (sb.Length % 2 != 0) { throw new ArgumentException("String must represent a valid hexadecimal (e.g. : 0F99DD)"); } var hexBytes = new Byte[sb.Length / 2]; try { for (var i = 0; i < hexBytes.Length; i++) { var stringIndex = i * 2; hexBytes[i] = Convert.ToByte(sb.ToString(stringIndex, 2), 16); } } catch (FormatException ex) { throw new ArgumentException("String must represent a valid hexadecimal (e.g. : 0F99DD)", ex); } return hexBytes; }
/// <summary> /// Default-ctor to build a plain literal with language /// </summary> public RDFPlainLiteral(String value, String language) : this(value) { if (language != null && Regex.IsMatch(language, "^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$")) { this.Language = language.ToUpperInvariant(); this.PatternMemberID = RDFModelUtilities.CreateHash(this.ToString()); } }
/// <summary> /// Asserts that the refId is in the proper format /// </summary> /// <param name="refId"></param> private void assertRefId(String refId) { Assert.AreEqual(32, refId.Length, "Length"); int pos = refId.IndexOf("-"); Assert.AreEqual(-1, pos, "Dashes"); // Assert case Assert.AreEqual(refId, refId.ToUpperInvariant(), "Case Compare"); }
/// <summary> /// Generate a thumbnail for a specified file /// </summary> /// <param name="background">The background color that item will have</param> /// <param name="pathToFile">The complete path to the file to open</param> /// <returns>The generated thumbnail</returns> private static Item GenerateCacheObjectThumbnail(Color background, String pathToFile) { Item ans = new Item(); int targetWidth = 128, targetHeight = 128; Image temp = null; /// Generate the thumbnail depending on the type of file if (pathToFile != null) { if (Constants.AllowedExtensionsImages().Any(pathToFile.ToUpperInvariant().EndsWith)) { using (FileStream fs = new FileStream(pathToFile, FileMode.Open, FileAccess.Read)) { using (Image image = Image.FromStream(fs, true, false)) { //temp = GenerateThumbnailPhoto(pathToFile); temp = ScaleImage(image, 128, 128); ans.Exif = GetExifFromImage(image); } } } else { using (MemoryStream memStream = new MemoryStream()) { FFMpegConverter ffmpeg = new FFMpegConverter(); ffmpeg.GetVideoThumbnail(pathToFile, memStream); using (Image image = Image.FromStream(memStream, true, false)) { temp = ScaleImage(image, 128, 128); } } } } Image target = new Bitmap(1, 1); (target as Bitmap).SetPixel(0, 0, background); target = new Bitmap(target, targetWidth, targetHeight); using (Graphics g = Graphics.FromImage(target)) { g.Clear(background); int x = (targetWidth - temp.Width) / 2; int y = (targetHeight - temp.Height) / 2; g.DrawImage(temp, x, y); } ans.Thumbnail = target; return ans; }
public static string ToInvariant(this string text) { List<char> newText = new List<char>(); foreach (char character in text) { string temp = new String(new char[] { character }); if (Char.IsUpper(character)) temp.ToUpperInvariant(); if (Char.IsLower(character)) temp.ToLowerInvariant(); foreach (char newchar in temp) { newText.Add(newchar); temp.NotNullOrDefault(""); } } return new String(newText.ToArray()); }
/// <summary> /// Default-ctor to build a filter on the given variable for the given language /// </summary> public RDFLangMatchesFilter(RDFVariable variable, String language) { if (variable != null) { if (language != null) { if (language == String.Empty || language == "*" || Regex.IsMatch(language, "^[a-zA-Z]+([\\-][a-zA-Z0-9]+)*$")) { this.Variable = variable; this.Language = language.ToUpperInvariant(); this.FilterID = RDFModelUtilities.CreateHash(this.ToString()); } else { throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"language\" parameter (" + language + ") does not represent a valid language."); } } else { throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"language\" parameter is null."); } } else { throw new RDFQueryException("Cannot create RDFLangMatchesFilter because given \"variable\" parameter is null."); } }
private String GetFilePath(String fileName) { if (!fileName.ToUpperInvariant().EndsWith(".VM")) { fileName += ".vm"; } String virtualPath1 = HttpContext.Current.Server.MapPath(String.Concat("/sites/", this.domainName, "/view/", fileName.Trim('/', '\\'))); if (File.Exists(virtualPath1)) { return virtualPath1; } String virtualPath2 = HttpContext.Current.Server.MapPath(String.Concat("/sites/default/view/", fileName.Trim('/', '\\'))); if (File.Exists(virtualPath2)) { return virtualPath2; } throw new global::NVelocity.Exception.ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, "Template '{0}' not found", fileName)); }
/// <inheritdoc/> public override String GetPaging(String sql, String order, Int32 limit, Int32 offset) { if (offset > 0) { if (String.IsNullOrEmpty(order)) throw new ArgumentException("An order should be specified for paging query.", "order"); sql = new StringBuilder(sql.Length + order.Length + 9) .Append(sql) .Append(" ") .Append(order) .Insert(GetAfterSelectInsertPoint(sql), " TOP " + (limit + offset)) .ToString(); String anotherOrderby = order.ToUpperInvariant(); if (anotherOrderby.Contains(" DESC")) anotherOrderby = anotherOrderby.Replace(" DESC", " ASC"); else if (anotherOrderby.Contains(" ASC")) anotherOrderby = anotherOrderby.Replace(" ASC", " DESC"); else anotherOrderby += " DESC"; // NOTE This may not work properly when the total count of records < (limit + offset) return new StringBuilder("SELECT * FROM (SELECT top ") .Append(limit) .Append(" * FROM (") .Append(sql) .Append(") t1 ") .Append(anotherOrderby) .Append(") t2 ") .Append(order) .ToString(); } else { return new StringBuilder(sql.Length + (order == null ? 0 : order.Length) + 9) .Append(sql) .Append(" ") .Append(order) .Insert(GetAfterSelectInsertPoint(sql), " TOP " + limit) .ToString(); } }
public static String ToNumber(String raw) { if (String.IsNullOrWhiteSpace(raw)) return ""; else raw = raw.ToUpperInvariant(); var newNumber = new StringBuilder(); foreach (var c in raw) { if (" -0123456789".Contains(c)) newNumber.Append(c); else { var result = TranslateToNumber(c); if (result != null) newNumber.Append(result); } //ohterwise a nonnumeric char is skipped } return newNumber.ToString(); }
public IEnumerable<ICodeSnippet> GetSnippets(SqlDocumentRepository sqlDocumentRepository, string statementText, int cursorPosition) { if (sqlDocumentRepository?.Statements == null) { return EmptyCollection; } var statement = sqlDocumentRepository.Statements.TakeWhile(s => s.SourcePosition.IndexStart <= cursorPosition - 1).LastOrDefault(); StatementGrammarNode currentNode = null; if (statement != null) { currentNode = statement.GetTerminalAtPosition(cursorPosition) ?? statement.GetNearestTerminalToPosition(cursorPosition); } if (currentNode != null && String.Equals(currentNode.Id, OracleGrammarDescription.Terminals.RightParenthesis) && !String.Equals(currentNode.ParentNode.Id, OracleGrammarDescription.NonTerminals.CommonTableExpression) && currentNode.PrecedingTerminal?.PrecedingTerminal != null) { currentNode = currentNode.PrecedingTerminal.PrecedingTerminal; } var textToReplace = new String(statementText.Substring(0, cursorPosition).Reverse().TakeWhile(c => !c.In(' ', '\n', '\t', '(', '\r', ';')).Reverse().ToArray()); if (String.IsNullOrWhiteSpace(textToReplace)) { return EmptyCollection; } var candidates = OracleSqlParser.Instance.GetTerminalCandidates(currentNode).Select(c => c.Id); return Snippets.SnippetCollection.Where(s => s.Name.ToUpperInvariant().Contains(textToReplace.ToUpperInvariant()) && (s.AllowedTerminals == null || s.AllowedTerminals.Length == 0 || s.AllowedTerminals.Select(t => t.Id).Intersect(candidates).Any())) .Select(s => BuildCodeSnippet(s, SourcePosition.Create(cursorPosition - textToReplace.Length, cursorPosition))).ToArray(); }
/// <summary> /// Parses an ImportanceType from a given Importance header value. /// </summary> /// <param name="headerValue">The value to be parsed</param> /// <returns>A <see cref="MailPriority"/>. If the <paramref name="headerValue"/> is not recognized, Normal is returned.</returns> /// <exception cref="ArgumentNullException">If <paramref name="headerValue"/> is <see langword="null"/></exception> public static MailPriority ParseImportance(String headerValue) { if (headerValue == null) throw new ArgumentNullException("headerValue"); switch (headerValue.ToUpperInvariant()) { case "5": case "HIGH": return MailPriority.High; case "3": case "NORMAL": return MailPriority.Normal; case "1": case "LOW": return MailPriority.Low; default: return MailPriority.Normal; } }
/// <summary>Try to parse a script line into commands and arguments</summary> /// <param name="line">The line to parse</param> /// <param name="commandData">A <seealso cref="CommandData"/> object with commands and keystrokes</param> /// <returns>true on success, false on failure, CommandData will be null for commands not requiring data to be sent</returns> public static bool TryParseScriptLine(String line, out CommandData commandData) { commandData = null; if (string.IsNullOrEmpty(line) || line.StartsWith("#")) // a comment line, ignore { return false; } string command = string.Empty; string args = string.Empty; int index = line.IndexOf(' '); if (index > 0) { command = line.Substring(0, index); args = line.Substring(index + 1).TrimEnd(); } else { command = line.ToUpperInvariant().TrimEnd(); } // lookup command and execute action associated with it. Func<String, CommandData> spslCommand = MatchCommand(command); if (spslCommand != null) { commandData = spslCommand(args); return true; } else { Log.WarnFormat("Command {0} Not Supported", command); return false; } }
/// <summary> /// Determines if the message /// </summary> /// <param name="command"></param> /// <returns></returns> public virtual Boolean CanParseDccCommand( String command ) { if ( String.IsNullOrEmpty( command ) ) { return false; } return ( DccCommand.ToUpperInvariant().EndsWith( command.ToUpperInvariant(), StringComparison.Ordinal ) ); }
private void RedrawWindow(User32.RECT rect) { }// => User32.InvalidateRect(this.LVHandle, ref rect, false); /// <summary> /// Returns the index of the first item whose display name starts with the search string. /// </summary> /// <param name="search"> The string for which to search for. </param> /// <param name="startindex"> /// The index from which to start searching. Enter '0' to search all items. /// </param> /// <returns> The index of an item within the list view. </returns> private Int32 GetFirstIndexOf(String search, Int32 startindex) { Int32 i = startindex; while (true) { if (i >= Items.Count) return -1; else if (Items[i].DisplayName.ToUpperInvariant().StartsWith(search.ToUpperInvariant())) return i; else i++; } }
/// <summary> /// Looks to see if the switch is in the array. /// </summary> /// <param name="switchArray"> /// The switch array. /// </param> /// <param name="value"> /// The value. /// </param> /// <returns> /// The index of the switch. /// </returns> private Int32 IsSwitchInArray(String[] switchArray, String value) { String valueCompare = value; if (this.caseSensitiveSwitches) { valueCompare = value.ToUpperInvariant(); } Int32 retValue = -1; for (Int32 n = 0; n < switchArray.Length; n++) { String currSwitch = switchArray[n]; if (this.caseSensitiveSwitches) { currSwitch = currSwitch.ToUpperInvariant(); } if (0 == String.CompareOrdinal(valueCompare, currSwitch)) { retValue = n; break; } } return retValue; }
/*public override long GetItemId (int position) { return _Posts [position].Id; }*/ public static SpannableString BuildBackgroundColorSpan(SpannableString spannableString, String text, String searchString, Color color) { int indexOf = text.ToUpperInvariant().IndexOf(searchString.ToUpperInvariant()); try { spannableString.SetSpan(new BackgroundColorSpan(color), indexOf, (indexOf + searchString.Length),SpanTypes.ExclusiveExclusive); } catch (Exception e) { } return spannableString; }
/// <summary> /// Determines if the message's DCC command is compatible with this message. /// </summary> public override Boolean CanParseDccCommand( String command ) { if ( String.IsNullOrEmpty( command ) ) { return false; } return command.ToUpperInvariant().EndsWith( "CHAT", StringComparison.Ordinal ); }
/// <summary> /// Parse a character set into an encoding. /// </summary> /// <param name="characterSet">The character set to parse</param> /// <returns>An encoding which corresponds to the character set</returns> /// <exception cref="ArgumentNullException">If <paramref name="characterSet"/> is <see langword="null"/></exception> public static Encoding ParseCharsetToEncoding(String characterSet) { if (characterSet == null) throw new ArgumentNullException("characterSet"); String charSetUpper = characterSet.ToUpperInvariant(); if (charSetUpper.Contains("WINDOWS") || charSetUpper.Contains("CP")) { // It seems the character set contains an codepage value, which we should use to parse the encoding charSetUpper = charSetUpper.Replace("CP", ""); // Remove cp charSetUpper = charSetUpper.Replace("WINDOWS", ""); // Remove windows charSetUpper = charSetUpper.Replace("-", ""); // Remove - which could be used as cp-1554 // Now we hope the only thing left in the characterSet is numbers. Int32 codepageNumber = Int32.Parse(charSetUpper, CultureInfo.InvariantCulture); return Encoding.GetEncoding(codepageNumber); } // Some emails incorrectly specify the encoding to be utf8 - but it has to be utf-8 if (characterSet.Equals("utf8", StringComparison.InvariantCultureIgnoreCase)) characterSet = "utf-8"; // It seems there is no codepage value in the characterSet. It must be a named encoding return Encoding.GetEncoding(characterSet); }
/// <summary> /// Decode a Base32 encoded string into an array of binary bytes. /// May fail if the parameter is a non canonical Base32 string /// (the only other possible exception is that the /// returned array cannot be allocated in memory) /// </summary> /// <param name="encoded">The encoded value.</param> /// <returns></returns> public static byte[] Decode(String encoded) { if (encoded == null) throw new ArgumentNullException("encoded"); // clean up // all to uppercase, 1 and 0 do not exist in the vocabulary, probably mistyped? encoded = encoded.ToUpperInvariant().Replace('0', 'O').Replace('1', 'I'); char[] chars = encoded.ToCharArray(); // avoids using charAt() int charsLen = chars.Length; // Note that the code below detects could detect non canonical // Base32 length within the loop. However canonical Base32 length // can be tested before entering the loop. // A canonical Base32 length modulo 8 cannot be: // 1 (aborts discarding 5 bits at STEP n=0 which produces no byte), // 3 (aborts discarding 7 bits at STEP n=2 which produces no byte), // 6 (aborts discarding 6 bits at STEP n=1 which produces no byte). switch (charsLen & 7) { // test the length of last subblock case 1: // 5 bits in subblock: 0 useful bits but 5 discarded case 3: // 15 bits in subblock: 8 useful bits but 7 discarded case 6: // 30 bits in subblock: 24 useful bits but 6 discarded throw new ArgumentException(ERROR_NON_CANONICAL_LENGTH); } int charDigitsLen = charDigits.Length; int bytesLen = (charsLen*5) >> 3; byte[] bytes = new byte[bytesLen]; int bytesOffset = 0, charsOffset = 0; // Also the code below does test that other discarded bits // (1 to 4 bits at end) are effectively 0. while (charsLen > 0) { int digit, lastDigit; // STEP n = 0: Read the 1st Char in a 8-Chars subblock // Leave 5 bits, asserting there's another encoding Char if ((digit = chars[charsOffset] - charDigitsBase) < 0 || digit >= charDigitsLen || (digit = charDigits[digit]) == -1) throw new ArgumentException(ERROR_INVALID_CHAR); lastDigit = digit << 3; // STEP n = 5: Read the 2nd Char in a 8-Chars subblock // Insert 3 bits, leave 2 bits, possibly trailing if no more Char if ((digit = chars[charsOffset + 1] - charDigitsBase) < 0 || digit >= charDigitsLen || (digit = charDigits[digit]) == -1) throw new ArgumentException(ERROR_INVALID_CHAR); bytes[bytesOffset] = (byte) ((digit >> 2) | lastDigit); lastDigit = (digit & 3) << 6; if (charsLen == 2) { if (lastDigit != 0) throw new ArgumentException(ERROR_NON_CANONICAL_END); break; // discard the 2 trailing null bits } // STEP n = 2: Read the 3rd Char in a 8-Chars subblock // Leave 7 bits, asserting there's another encoding Char if ((digit = chars[charsOffset + 2] - charDigitsBase) < 0 || digit >= charDigitsLen || (digit = charDigits[digit]) == -1) throw new ArgumentException(ERROR_INVALID_CHAR); lastDigit |= (byte) (digit << 1); // STEP n = 7: Read the 4th Char in a 8-chars Subblock // Insert 1 bit, leave 4 bits, possibly trailing if no more Char if ((digit = chars[charsOffset + 3] - charDigitsBase) < 0 || digit >= charDigitsLen || (digit = charDigits[digit]) == -1) throw new ArgumentException(ERROR_INVALID_CHAR); bytes[bytesOffset + 1] = (byte) ((digit >> 4) | lastDigit); lastDigit = (byte) ((digit & 15) << 4); if (charsLen == 4) { if (lastDigit != 0) throw new ArgumentException(ERROR_NON_CANONICAL_END); break; // discard the 4 trailing null bits } // STEP n = 4: Read the 5th Char in a 8-Chars subblock // Insert 4 bits, leave 1 bit, possibly trailing if no more Char if ((digit = chars[charsOffset + 4] - charDigitsBase) < 0 || digit >= charDigitsLen || (digit = charDigits[digit]) == -1) throw new ArgumentException(ERROR_INVALID_CHAR); bytes[bytesOffset + 2] = (byte) ((digit >> 1) | lastDigit); lastDigit = (byte) ((digit & 1) << 7); if (charsLen == 5) { if (lastDigit != 0) throw new ArgumentException(ERROR_NON_CANONICAL_END); break; // discard the 1 trailing null bit } // STEP n = 1: Read the 6th Char in a 8-Chars subblock // Leave 6 bits, asserting there's another encoding Char if ((digit = chars[charsOffset + 5] - charDigitsBase) < 0 || digit >= charDigitsLen || (digit = charDigits[digit]) == -1) throw new ArgumentException(ERROR_INVALID_CHAR); lastDigit |= (byte) (digit << 2); // STEP n = 6: Read the 7th Char in a 8-Chars subblock // Insert 2 bits, leave 3 bits, possibly trailing if no more Char if ((digit = chars[charsOffset + 6] - charDigitsBase) < 0 || digit >= charDigitsLen || (digit = charDigits[digit]) == -1) throw new ArgumentException(ERROR_INVALID_CHAR); bytes[bytesOffset + 3] = (byte) ((digit >> 3) | lastDigit); lastDigit = (byte) ((digit & 7) << 5); if (charsLen == 7) { if (lastDigit != 0) throw new ArgumentException(ERROR_NON_CANONICAL_END); break; // discard the 3 trailing null bits } // STEP n = 3: Read the 8th Char in a 8-Chars subblock // Insert 5 bits, leave 0 bit, next encoding Char may not exist if ((digit = chars[charsOffset + 7] - charDigitsBase) < 0 || digit >= charDigitsLen || (digit = charDigits[digit]) == -1) throw new ArgumentException(ERROR_INVALID_CHAR); bytes[bytesOffset + 4] = (byte) (digit | lastDigit); //// This point is always reached for chars.length multiple of 8 charsOffset += 8; bytesOffset += 5; charsLen -= 8; } // On loop exit, discard the n trailing null bits return bytes; }
public static String GetAllowedDigests(String name) { string ret; allowedDigests.TryGetValue(name.ToUpperInvariant(), out ret); return ret; }
/// <summary> /// Parses a single header and sets member variables according to it. /// </summary> /// <param name="headerName">The name of the header</param> /// <param name="headerValue">The value of the header in unfolded state (only one line)</param> /// <exception cref="ArgumentNullException">If <paramref name="headerName"/> or <paramref name="headerValue"/> is <see langword="null"/></exception> public void ParseHeader(String headerName, String headerValue) { if (headerName == null) throw new ArgumentNullException("headerName"); if (headerValue == null) throw new ArgumentNullException("headerValue"); HeaderValueChanged(headerName, headerValue); switch (headerName.ToUpperInvariant()) { // See http://tools.ietf.org/html/rfc5322#section-3.6.3 case "TO": this.To = MessageHeader.ParseAddresses(headerValue); break; // See http://tools.ietf.org/html/rfc5322#section-3.6.3 case "CC": this.Cc = MessageHeader.ParseAddresses(headerValue); break; // See http://tools.ietf.org/html/rfc5322#section-3.6.3 case "BCC": this.Bcc = MessageHeader.ParseAddresses(headerValue); break; // See http://tools.ietf.org/html/rfc5322#section-3.6.2 case "FROM": // There is only one MailAddress in the from field this.From = MessageAddress.ParseAddress(headerValue); break; // http://tools.ietf.org/html/rfc5322#section-3.6.2 // The implementation here might be wrong case "REPLY-TO": // This field may actually be a list of addresses, but no // such case has been encountered this.ReplyTo = MessageAddress.ParseAddress(headerValue); break; // http://tools.ietf.org/html/rfc5322#section-3.6.2 case "SENDER": this.Sender = MessageAddress.ParseAddress(headerValue); break; // See http://tools.ietf.org/html/rfc5322#section-3.6.5 // RFC 5322: // The "Keywords:" field contains a comma-separated list of one or more // words or quoted-strings. // The field are intended to have only human-readable content // with information about the message case "KEYWORDS": String[] keywordsTemp = headerValue.Split(','); foreach (String keyword in keywordsTemp) { // Remove the quotes if there is any Keywords.Add(Utility.RemoveQuotesIfAny(keyword.Trim())); } break; // See http://tools.ietf.org/html/rfc5322#section-3.6.7 case "RECEIVED": // Simply add the value to the list Received.Add(headerValue.Trim()); break; case "IMPORTANCE": Importance = HeaderFieldParser.ParseImportance(headerValue.Trim()); break; // See http://tools.ietf.org/html/rfc3798#section-2.1 case "DISPOSITION-NOTIFICATION-TO": this.DispositionNotificationTo = MessageHeader.ParseAddresses(headerValue); break; case "MIME-VERSION": MimeVersion = headerValue.Trim(); break; // See http://tools.ietf.org/html/rfc5322#section-3.6.5 case "SUBJECT": case "THREAD-TOPIC": Subject = EncodedWord.Decode(headerValue); break; // See http://tools.ietf.org/html/rfc5322#section-3.6.7 case "RETURN-PATH": // Return-paths does not include a username, but we // may still use the address parser this.ReturnPath = MessageAddress.ParseAddress(headerValue); break; // See http://tools.ietf.org/html/rfc5322#section-3.6.4 // Example Message-ID // <*****@*****.**> case "MESSAGE-ID": MessageId = HeaderFieldParser.ParseId(headerValue); break; // See http://tools.ietf.org/html/rfc5322#section-3.6.4 case "IN-REPLY-TO": InReplyTo = HeaderFieldParser.ParseMultipleIDs(headerValue); break; // See http://tools.ietf.org/html/rfc5322#section-3.6.4 case "REFERENCES": References = HeaderFieldParser.ParseMultipleIDs(headerValue); break; // See http://tools.ietf.org/html/rfc5322#section-3.6.1)) case "DATE": Date = headerValue.Trim(); DateSent = Rfc2822DateTime.StringToDate(headerValue); break; // See http://tools.ietf.org/html/rfc2045#section-6 // See ContentTransferEncoding class for more details case "CONTENT-TRANSFER-ENCODING": ContentTransferEncoding = HeaderFieldParser.ParseContentTransferEncoding(headerValue.Trim()); break; // See http://tools.ietf.org/html/rfc2045#section-8 case "CONTENT-DESCRIPTION": // Human description of for example a file. Can be encoded ContentDescription = EncodedWord.Decode(headerValue.Trim()); break; // See http://tools.ietf.org/html/rfc2045#section-5.1 // Example: Content-type: text/plain; charset="us-ascii" case "CONTENT-TYPE": ContentType = HeaderFieldParser.ParseContentType(headerValue); break; // See http://tools.ietf.org/html/rfc2183 case "CONTENT-DISPOSITION": ContentDisposition = HeaderFieldParser.ParseContentDisposition(headerValue); break; // See http://tools.ietf.org/html/rfc2045#section-7 // Example: <foo4*[email protected]> case "CONTENT-ID": ContentId = HeaderFieldParser.ParseId(headerValue); break; case "_REQUEST-LINE_": // header could contain request-line that could not be parsed as simple key value pair, so store entire line // Example: POST /odata/$batch HTTP/1.1 RequestLine = headerValue; break; default: // This is an unknown header // Custom headers are allowed. That means headers // that are not mentionen in the RFC. // Such headers start with the letter "X" // We do not have any special parsing of such // Add it to unknown headers UnknownHeaders.Add(headerName, headerValue); break; } }
/// <summary> /// Adds a mime type to the files handler /// </summary> /// <param name="extension">The extension to match</param> /// <param name="mimeType">The mime type to return for files matching this extension</param> public void AddMimeType(String extension, String mimeType) { _mimeTypes.Add(extension.ToUpperInvariant().Trim(), mimeType.Trim()); }
/// <summary> /// Removes a mime type from the files handler /// </summary> /// <param name="extension">The extension to match</param> public void RemoveMimeType(String extension) { _mimeTypes.Remove(extension.ToUpperInvariant().Trim()); }
/// <summary> /// Updates current texture object from tree. /// </summary> /// <param name="treeInd">Index of texture in tree.</param> /// <param name="treetex">Tree texture object to get info from.</param> public void UpdateTex(int treeInd, TreeTexInfo treetex) { found = true; TreeInd = treeInd; TexName = treetex.TexName; // KFreon: Reorder files so DLC isn't first /*List<string> files = new List<string>(treetex.Files); List<int> ids = new List<int>(treetex.ExpIDs); int count = files.Count; int index = -1; if (files[0].Contains("DLC")) for (int i = 0; i < count; i++) if (!files[i].Contains("DLC")) { index = i; break; } if (index != -1) { string thing = files[index]; files.RemoveAt(index); files.Insert(0, thing); int thing2 = ids[index]; ids.RemoveAt(index); ids.Insert(0, thing2); } Files.AddRange(files); ExpIDs.AddRange(ids);*/ Files.AddRange(treetex.Files); ExpIDs.AddRange(treetex.ExpIDs); List<PCCExpID> things = new List<PCCExpID>(); for (int i = 0; i < Files.Count; i++) things.Add(new PCCExpID(Files[i], ExpIDs[i])); // KFreon: Reorder ME1 files if (GameVersion == 1) { things = things.OrderByDescending(t => t.file.Length).ToList(); Files.Clear(); ExpIDs.Clear(); foreach (var item in things) { Files.Add(item.file); ExpIDs.Add(item.expid); } } //ExpIDs.AddRange(treetex.ExpIDs); OriginalFiles = new List<string>(Files); OriginalExpIDs = new List<int>(ExpIDs); ExpectedMips = treetex.NumMips; ExpectedFormat = treetex.Format.Replace("PF_", ""); if (ExpectedFormat.ToUpperInvariant().Contains("NORMALMAP")) ExpectedFormat = "ATI2_3Dc"; if (ExpectedFormat.ToUpperInvariant().Contains("A8R8G8B8")) ExpectedFormat = "ARGB"; // KFreon: File Dups List<TPFTexInfo> dups = new List<TPFTexInfo>(FileDuplicates); FileDuplicates.Clear(); foreach (TPFTexInfo tex in dups) { TPFTexInfo texn = tex; texn.found = true; texn.TreeInd = TreeInd; texn.TexName = treetex.TexName; texn.Files.AddRange(treetex.Files); texn.ExpIDs.AddRange(treetex.ExpIDs); texn.ExpectedFormat = treetex.Format; texn.ExpectedMips = treetex.NumMips; texn.OriginalExpIDs = new List<int>(ExpIDs); texn.OriginalFiles = new List<string>(Files); FileDuplicates.Add(texn); } ValidDimensions = ValidateDimensions(); }
public MultiLanguageString(string sValue) { int nStartTag = sValue.IndexOf('['); while (nStartTag >= 0) { int nEndTag = sValue.IndexOf(']', nStartTag); if (nEndTag > nStartTag) { String sLang = sValue.Substring(nStartTag + 1, nEndTag - (nStartTag + 1)); Boolean bOkIso = false; if (sLang.Length == 2) { if (Char.IsLetter(sLang[0]) && Char.IsLetter(sLang[1])) { bOkIso = true; } } else if (sLang.Length == 5) { if (Char.IsLetter(sLang[0]) && Char.IsLetter(sLang[1]) && sLang[2] == '-' && Char.IsLetter(sLang[3]) && Char.IsLetter(sLang[4])) { bOkIso = true; } } if (bOkIso) { int nEnd = sValue.IndexOf("[/" + sLang + "]", nEndTag);//check for language end if (nEnd > nEndTag) { string sLocale = sValue.Substring(nEndTag + 1, nEnd - (nEndTag + 1)); //extract string //unescape sLocale = sLocale.Replace("\\\\", "\\"); sLocale = sLocale.Replace("\\]", "]"); _oLocales[sLang.ToUpperInvariant()] = sLocale; nStartTag = sValue.IndexOf('[', nEnd + 1); } else { nStartTag = sValue.IndexOf('[', nEndTag + 1); } } else { nStartTag = sValue.IndexOf('[', nEndTag + 1); } } else { nStartTag = sValue.IndexOf('[', nStartTag + 1); } } /* RX * MatchCollection oCol = _oLngRX.Matches(sValue); * foreach(Match oMatch in oCol) * { * * String sTag = oMatch.Groups[1].Value; * String sContent = oMatch.Groups[3].Value; * sContent = sContent.Replace("\\\\", "\\"); * sContent = sContent.Replace("\\]", "]"); * _oLocales[sTag.ToUpperInvariant()] = sContent; * }*/ /* CHAR PARSING * StringBuilder sTag = new StringBuilder(); * StringBuilder sCloseTag = new StringBuilder(); * StringBuilder sLocale = new StringBuilder(); * CursorIn oPlace = CursorIn.Void; * for(int i = 0 ; i < sValue.Length ; i++) * { * char oChar = sValue[i]; * switch(oPlace) * { * case CursorIn.OpenTag: * { * if(oChar == '/') * { * oPlace = CursorIn.CloseTag; * sCloseTag.Append("[/"); * } * else if(oChar == ']') * oPlace = CursorIn.Content; * else * sTag.Append(oChar); * } * break; * case CursorIn.CloseTag: * { * if(oChar == ']') * { * String sParsedEndTag = sCloseTag.ToString(); * String sParsedStartTag = sTag.ToString(); * if(sParsedEndTag.EndsWith("\\") || sParsedEndTag != "[/" + sParsedStartTag) * { * sParsedEndTag += "]"; * sParsedEndTag = sParsedEndTag.Replace("\\\\", "\\"); * sParsedEndTag = sParsedEndTag.Replace("\\]", "]"); * sLocale.Append(sParsedEndTag); * sCloseTag.Length = 0; * } * else * { * oPlace = CursorIn.Void; * String sTagIso = sTag.ToString(); * String sContent = sLocale.ToString(); * //sContent = sContent.Replace("\\\\", "\\"); * //sContent = sContent.Replace("\\]", "]"); * _oLocales[sTagIso.ToUpperInvariant()] = sContent; * sTag.Length = 0; * sLocale.Length = 0; * } * } * else * sCloseTag.Append(oChar); * } * break; * case CursorIn.Content: * { * if(oChar == '[') * oPlace = CursorIn.OpenTag; * else if(oChar == '\\') * { * if(++i < sValue.Length-1) * sLocale.Append(sValue[i]); * } * else * sLocale.Append(oChar); * } * break; * case CursorIn.Void: * default: * { * if(oChar == '[') * oPlace = CursorIn.OpenTag; * } * break; * } * } * if(oPlace == CursorIn.Void && sTag.Length != 0) * _oLocales[sTag.ToString().ToUpperInvariant()] = sLocale.ToString();*/ }
private UrlRoute DiscoverRoute(Uri url, String method) { UrlRoute route = null; String path = url.AbsolutePath; var myRoutes = routes.OrderBy(r => r.Priority).Where(r => r.HttpMethod.ToUpperInvariant() == method.ToUpperInvariant()); foreach(UrlRoute myRoute in myRoutes) { if (myRoute.RouteRegex.IsMatch(path)) { route = myRoute; } } return route; }
public String FormatIdentifier(String identifier) { if (Util.IsQuotedName(identifier)) identifier = Util.UnquoteName(identifier); else { if (_providerInfo.IdentifierCase == IdentifierCase.Insensitive) identifier = identifier.ToUpperInvariant(); } if (RequiresQuoting(identifier)) { StringBuilder sb = new StringBuilder(); sb.Append(LeftQuote); sb.Append(identifier); sb.Append(RightQuote); return sb.ToString(); } else return identifier; }