public Attachment NewAttachment(Skin skin, AttachmentType type, String name) { if (type != AttachmentType.region) throw new Exception("Unknown attachment type: " + type); // Strip folder names. int index = name.LastIndexOfAny(new char[] {'/', '\\'}); if (index != -1) name = name.Substring(index + 1); tk2dSpriteDefinition def = sprites.GetSpriteDefinition(name); if (def == null) throw new Exception("Sprite not found in atlas: " + name + " (" + type + ")"); if (def.complexGeometry) throw new NotImplementedException("Complex geometry is not supported: " + name + " (" + type + ")"); if (def.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW) throw new NotImplementedException("Only 2D Toolkit atlases are supported: " + name + " (" + type + ")"); RegionAttachment attachment = new RegionAttachment(name); Vector2 minTexCoords = Vector2.one; Vector2 maxTexCoords = Vector2.zero; for (int i = 0; i < def.uvs.Length; ++i) { Vector2 uv = def.uvs[i]; minTexCoords = Vector2.Min(minTexCoords, uv); maxTexCoords = Vector2.Max(maxTexCoords, uv); } bool rotated = def.flipped == tk2dSpriteDefinition.FlipMode.Tk2d; if (rotated) { float temp = minTexCoords.x; minTexCoords.x = maxTexCoords.x; maxTexCoords.x = temp; } attachment.SetUVs( minTexCoords.x, maxTexCoords.y, maxTexCoords.x, minTexCoords.y, rotated ); attachment.RegionOriginalWidth = (int)(def.untrimmedBoundsData[1].x / def.texelSize.x); attachment.RegionOriginalHeight = (int)(def.untrimmedBoundsData[1].y / def.texelSize.y); attachment.RegionWidth = (int)(def.boundsData[1].x / def.texelSize.x); attachment.RegionHeight = (int)(def.boundsData[1].y / def.texelSize.y); float x0 = def.untrimmedBoundsData[0].x - def.untrimmedBoundsData[1].x / 2; float x1 = def.boundsData[0].x - def.boundsData[1].x / 2; attachment.RegionOffsetX = (int)((x1 - x0) / def.texelSize.x); float y0 = def.untrimmedBoundsData[0].y - def.untrimmedBoundsData[1].y / 2; float y1 = def.boundsData[0].y - def.boundsData[1].y / 2; attachment.RegionOffsetY = (int)((y1 - y0) / def.texelSize.y); attachment.RendererObject = def.material; return attachment; }
public Attachment NewAttachment(Skin skin, AttachmentType type, String name) { if (type != AttachmentType.region) throw new Exception("Unknown attachment type: " + type); // Strip folder names. int index = name.LastIndexOfAny(new char[] {'/', '\\'}); if (index != -1) name = name.Substring(index + 1); tk2dSpriteDefinition attachmentParameters = null; for (int i = 0; i < sprites.inst.spriteDefinitions.Length; ++i) { tk2dSpriteDefinition def = sprites.inst.spriteDefinitions[i]; if (def.name == name) { attachmentParameters = def; break; } } if (attachmentParameters == null) throw new Exception("Sprite not found in atlas: " + name + " (" + type + ")"); if (attachmentParameters.complexGeometry) throw new NotImplementedException("Complex geometry is not supported: " + name + " (" + type + ")"); if (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW) throw new NotImplementedException("Only 2D Toolkit atlases are supported: " + name + " (" + type + ")"); Vector2 minTexCoords = Vector2.one; Vector2 maxTexCoords = Vector2.zero; for (int i = 0; i < attachmentParameters.uvs.Length; ++i) { Vector2 uv = attachmentParameters.uvs[i]; minTexCoords = Vector2.Min(minTexCoords, uv); maxTexCoords = Vector2.Max(maxTexCoords, uv); } Texture texture = attachmentParameters.material.mainTexture; int width = (int)(Mathf.Abs(maxTexCoords.x - minTexCoords.x) * texture.width); int height = (int)(Mathf.Abs(maxTexCoords.y - minTexCoords.y) * texture.height); bool rotated = (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.Tk2d); if (rotated) { float temp = minTexCoords.x; minTexCoords.x = maxTexCoords.x; maxTexCoords.x = temp; } RegionAttachment attachment = new RegionAttachment(name); attachment.SetUVs( minTexCoords.x, maxTexCoords.y, maxTexCoords.x, minTexCoords.y, rotated ); // TODO - Set attachment.RegionOffsetX/Y. What units does attachmentParameters.untrimmedBoundsData use?! attachment.RegionWidth = width; attachment.RegionHeight = height; attachment.RegionOriginalWidth = width; attachment.RegionOriginalHeight = height; return attachment; }
public StatManager(String SaveStatePath) { if (string.IsNullOrEmpty(SaveStatePath)) { logger.Error("SaveStatePath was null or empty."); throw new ArgumentNullException("SaveStatePath Can't be Null or Empty String. "); } if (SaveStatePath.LastIndexOfAny(Path.GetInvalidPathChars()) >= 0) { logger.Error("Invalid Path Characters In SaveStatePath=\"{0}\")", SaveStatePath); throw new ArgumentException("Invalid Characters In Path"); } if (SaveStatePath.Any( x => char.IsWhiteSpace ( x ))) { logger.Error("Whitespace Characters In SaveStatePath=\"{0}\" ", SaveStatePath); throw new ArgumentException("WhiteSpace Characters In Path"); } logger.Info("Called with (SaveStatePath=\"{0}\")", SaveStatePath); LoadSaveState(SaveStatePath); _savestatepath = SaveStatePath; }
private void ProcessSpriteDefinition (String name) { // Strip folder names. int index = name.LastIndexOfAny(new char[] {'/', '\\'}); if (index != -1) name = name.Substring(index + 1); tk2dSpriteDefinition def = sprites.inst.GetSpriteDefinition(name); if (def == null) { Debug.Log("Sprite not found in atlas: " + name, sprites); throw new Exception("Sprite not found in atlas: " + name); } if (def.complexGeometry) throw new NotImplementedException("Complex geometry is not supported: " + name); if (def.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW) throw new NotImplementedException("Only 2D Toolkit atlases are supported: " + name); Vector2 minTexCoords = Vector2.one, maxTexCoords = Vector2.zero; for (int i = 0; i < def.uvs.Length; ++i) { Vector2 uv = def.uvs[i]; minTexCoords = Vector2.Min(minTexCoords, uv); maxTexCoords = Vector2.Max(maxTexCoords, uv); } regionRotated = def.flipped == tk2dSpriteDefinition.FlipMode.Tk2d; if (regionRotated) { float temp = minTexCoords.x; minTexCoords.x = maxTexCoords.x; maxTexCoords.x = temp; } u = minTexCoords.x; v = maxTexCoords.y; u2 = maxTexCoords.x; v2 = minTexCoords.y; regionOriginalWidth = (int)(def.untrimmedBoundsData[1].x / def.texelSize.x); regionOriginalHeight = (int)(def.untrimmedBoundsData[1].y / def.texelSize.y); regionWidth = (int)(def.boundsData[1].x / def.texelSize.x); regionHeight = (int)(def.boundsData[1].y / def.texelSize.y); float x0 = def.untrimmedBoundsData[0].x - def.untrimmedBoundsData[1].x / 2; float x1 = def.boundsData[0].x - def.boundsData[1].x / 2; regionOffsetX = (int)((x1 - x0) / def.texelSize.x); float y0 = def.untrimmedBoundsData[0].y - def.untrimmedBoundsData[1].y / 2; float y1 = def.boundsData[0].y - def.boundsData[1].y / 2; regionOffsetY = (int)((y1 - y0) / def.texelSize.y); material = def.materialInst; }
/// <summary> /// Parse a rfc 2822 date and time specification. rfc 2822 section 3.3 /// </summary> /// <param name="date">rfc 2822 date-time</param> /// <returns>A <see cref="System.DateTime" /> from the parsed header body</returns> public static System.DateTime parseDate(System.String date) { if (date == null || date.Equals(System.String.Empty)) { return(System.DateTime.MinValue); } System.DateTime msgDateTime; date = anmar.SharpMimeTools.SharpMimeTools.uncommentString(date); msgDateTime = new System.DateTime(0); try { // TODO: Complete the list date = date.Replace("UT", "+0000"); date = date.Replace("GMT", "+0000"); date = date.Replace("EDT", "-0400"); date = date.Replace("EST", "-0500"); date = date.Replace("CDT", "-0500"); date = date.Replace("MDT", "-0600"); date = date.Replace("MST", "-0600"); date = date.Replace("EST", "-0700"); date = date.Replace("PDT", "-0700"); date = date.Replace("PST", "-0800"); date = date.Replace("AM", System.String.Empty); date = date.Replace("PM", System.String.Empty); int rpos = date.LastIndexOfAny(new Char[] { ' ', '\t' }); if (rpos > 0 && rpos != date.Length - 6) { date = date.Substring(0, rpos + 1) + "-0000"; } date = date.Insert(date.Length - 2, ":"); msgDateTime = DateTime.ParseExact(date, _date_formats, System.Globalization.CultureInfo.CreateSpecificCulture("en-us"), System.Globalization.DateTimeStyles.AllowInnerWhite); #if LOG } catch (System.Exception e) { if (log.IsErrorEnabled) { log.Error(System.String.Concat("Error parsing date: [", date, "]"), e); } #else } catch (System.Exception) { #endif msgDateTime = new System.DateTime(0); } return(msgDateTime); }
/// <summary> /// Parse a rfc 2822 date and time specification. rfc 2822 section 3.3 /// </summary> /// <param name="date">rfc 2822 date-time</param> /// <returns>A <see cref="System.DateTime" /> from the parsed header body</returns> public static DateTime parseDate( String date ) { if ( date==null || date.Equals(String.Empty) ) return DateTime.MinValue; DateTime msgDateTime; date = SharpMimeTools.SharpMimeTools.uncommentString (date); msgDateTime = new DateTime (0); try { // TODO: Complete the list date = date.Replace("UT", "+0000"); date = date.Replace("GMT", "+0000"); date = date.Replace("EDT", "-0400"); date = date.Replace("EST", "-0500"); date = date.Replace("CDT", "-0500"); date = date.Replace("MDT", "-0600"); date = date.Replace("MST", "-0600"); date = date.Replace("EST", "-0700"); date = date.Replace("PDT", "-0700"); date = date.Replace("PST", "-0800"); date = date.Replace("AM", String.Empty); date = date.Replace("PM", String.Empty); int rpos = date.LastIndexOfAny(new Char[]{' ', '\t'}); if (rpos>0 && rpos != date.Length - 6) date = date.Substring(0, rpos + 1) + "-0000"; date = date.Insert(date.Length-2, ":"); msgDateTime = DateTime.ParseExact(date, _date_formats, CultureInfo.CreateSpecificCulture("en-us"), DateTimeStyles.AllowInnerWhite); #if LOG } catch ( System.Exception e ) { if ( log.IsErrorEnabled ) log.Error(System.String.Concat("Error parsing date: [", date, "]"), e); #else } catch ( Exception ) { #endif msgDateTime = new DateTime (0); } return msgDateTime; }
internal void loadFile(String filename) { if (string.IsNullOrEmpty(luaFile)) throw new Exception("No Lua file specified"); if (!System.IO.File.Exists(filename)) throw new Exception("Cannot find file " + filename); // store the file data this.theData = System.IO.File.ReadAllBytes(filename); interp = new Lua(); this.usedSetData = false; #region register predefined functions & variables // register the functions interp.RegisterFunction("read", this, this.GetType().GetMethod("read")); interp.RegisterFunction("read2", this, this.GetType().GetMethod("read2")); interp.RegisterFunction("readWORD", this, this.GetType().GetMethod("readWORD")); interp.RegisterFunction("readlWORD", this, this.GetType().GetMethod("readlWORD")); interp.RegisterFunction("readDWORD", this, this.GetType().GetMethod("readDWORD")); interp.RegisterFunction("readlDWORD", this, this.GetType().GetMethod("readlDWORD")); interp.RegisterFunction("readString", this, this.GetType().GetMethod("readString")); interp.RegisterFunction("readString2", this, this.GetType().GetMethod("readString2")); interp.RegisterFunction("stringToInt", this, this.GetType().GetMethod("stringToInt")); interp.RegisterFunction("setData", this, this.GetType().GetMethod("setData")); interp.RegisterFunction("setData2", this, this.GetType().GetMethod("setData2")); interp.RegisterFunction("addData", this, this.GetType().GetMethod("addData")); interp.RegisterFunction("addData2", this, this.GetType().GetMethod("addData2")); interp.RegisterFunction("toHexadecimal", this, this.GetType().GetMethod("ToHexadecimal")); // register the default variables interp["filesize"] = theData.Length; interp["filename"] = filename.Substring(filename.LastIndexOfAny(new char[] { '\\', '/' }) + 1); interp["filepath"] = filename.Substring(0, filename.LastIndexOfAny(new char[] { '\\', '/' }) + 1); #endregion // read the plugin try { interp.DoFile(this.luaFile); // if the variable invalid has been set, display it, and reset the data if (interp["invalid"] != null) { MainWindow.ShowError(interp.GetString("invalid")); this.bData.Data = new byte[0]; } else { #region format // try to read the format if (interp["format"] != null) { int format = (int)(double)interp["format"]; switch (this.Parent.BindingType) { case BindingType.GRAPHICS: if (format < 1 || format > 7) MainWindow.ShowError("Plugin warning: the format of the graphics should range from 1 up to and including 7.\n" + "Value " + format + " is ignored"); else GraphicsData.GraphFormat = (GraphicsFormat)format; break; case BindingType.PALETTE: if (format < 5 || format > 7) MainWindow.ShowError("Plugin warning: the format of the palette should range from 5 up to and including 7.\n" + "Value " + format + " is ignored"); else PaletteData.PalFormat = (PaletteFormat)format; break; } } #endregion if (this.parentBinding.BindingType == BindingType.PALETTE || (int)GraphicsData.GraphFormat >= 5) { #region palette order if (interp["order"] != null) { string s = ((string)interp["order"]).ToUpper(); if (s.Length != 3 || !s.Contains("R") || !s.Contains("G") || !s.Contains("B")) MainWindow.ShowError("Plugin warning: the colour order is invalid.\n" + "Value " + s + " is ignored."); else PaletteData.PalOrder = (PaletteOrder)Enum.Parse(typeof(PaletteOrder), s); } #endregion #region alpha location if (interp["alphaAtStart"] != null) { bool atStart = (bool)interp["alphaAtStart"]; PaletteData.AlphaSettings.Location = atStart ? AlphaLocation.START : AlphaLocation.END; } #endregion #region ignore alpha if (interp["ignoreAlpha"] != null) { bool ignore = (bool)interp["ignoreAlpha"]; PaletteData.AlphaSettings.IgnoreAlpha = ignore; } #endregion #region enable stretch if (interp["enableAlphaStrech"] != null) { bool enable = (bool)interp["enableAlphaStrech"]; PaletteData.AlphaSettings.Stretch = enable; } #endregion #region stretch settings if (interp["alphaStretch"] != null) { LuaTable t = interp.GetTable("alphaStretch"); if (t["min"] != null) PaletteData.AlphaSettings.Minimum = (byte)(double)t["min"]; else if(t[0] != null) PaletteData.AlphaSettings.Minimum = (byte)(double)t[0]; if (t["max"] != null) PaletteData.AlphaSettings.Maximum = (byte)(double)t["max"]; else if (t[0] != null) PaletteData.AlphaSettings.Maximum = (byte)(double)t[1]; } #endregion } #region Endianness if (interp["bigendian"] != null) { bool isBE = (bool)interp["bigendian"]; switch (this.Parent.BindingType) { case BindingType.GRAPHICS: GraphicsData.IsBigEndian = isBE; break; case BindingType.PALETTE: PaletteData.IsBigEndian = isBE; break; } } #endregion #region tile size if (interp["tilesize"] != null) { System.Drawing.Point size, oldSize; switch(this.parentBinding.BindingType) { case BindingType.GRAPHICS: size = oldSize = GraphicsData.TileSize; break; case BindingType.PALETTE: size = oldSize = PaletteData.TileSize; break; default: throw new Exception(string.Format("Unknown BindingType {0:s}", this.parentBinding.BindingType.ToString())); } try { LuaTable t = interp.GetTable("tilesize"); if (t["x"] != null) size.X = (int)(double)t["x"]; else if (t[0] != null) size.X = (int)(double)t[0]; if (t["y"] != null) size.Y = (int)(double)t["y"]; else if (t[1] != null) size.Y = (int)(double)t[1]; switch (this.parentBinding.BindingType) { case BindingType.GRAPHICS: GraphicsData.TileSize = size; break; case BindingType.PALETTE: PaletteData.TileSize = size; break; } } catch (Exception) { MainWindow.ShowError("Plugin warning: invalid tile size provided.\nValue is ignored."); switch (this.parentBinding.BindingType) { case BindingType.GRAPHICS: GraphicsData.TileSize = oldSize; break; case BindingType.PALETTE: PaletteData.TileSize = oldSize; break; } } } #endregion #region tiled if (interp["tiled"] != null) { bool tl; switch (this.parentBinding.BindingType) { case BindingType.GRAPHICS: tl = GraphicsData.Tiled; try { GraphicsData.Tiled = (bool)interp["tiled"]; } catch (Exception) { MainWindow.ShowError("Plugin warning: invalid tile size provided.\nValue is ignored."); GraphicsData.Tiled = tl; } break; case BindingType.PALETTE: tl = PaletteData.Tiled; try { PaletteData.Tiled = (bool)interp["tiled"]; } catch (Exception) { MainWindow.ShowError("Plugin warning: invalid tile size provided.\nValue is ignored."); PaletteData.Tiled = tl; } break; default: throw new Exception(string.Format("Unknown BindingType {0:s}", this.parentBinding.BindingType.ToString())); } } #endregion if (this.Parent.BindingType == BindingType.GRAPHICS) { #region width if (interp["width"] != null) { uint origW = GraphicsData.Width; try { uint w = (uint)(double)interp["width"]; GraphicsData.Width = w; } catch (Exception) { GraphicsData.Width = origW; MainWindow.ShowError("Plugin warning: invalid width.\n" + "Value " + interp.GetString("width") + " is ignored."); } } #endregion #region height if (interp["height"] != null) { uint origH = GraphicsData.Height; try { uint h = (uint)(double)interp["height"]; GraphicsData.Height = h; } catch (Exception) { GraphicsData.Height = origH; MainWindow.ShowError("Plugin warning: invalid height.\n" + "Value " + interp.GetString("height") + " is ignored."); } } #endregion } if (!usedSetData) this.bData.Data = this.theData; if (interp["warning"] != null) MainWindow.ShowWarning(interp.GetString("warning")); } } catch (Exception e) { MainWindow.ShowError("Plugin error: \n" + e.Message); } // close and delete the interpreter, and delete the data interp.Close(); interp = null; this.theData = null; }
public Boolean runTest () { System.Console.Error.WriteLine("String.LastIndexOfAny: Co1161LIO runTest starting..."); int iCountErrors = 0, iCountTestcases = 0; int n2 = -2; System.String swrString2 = null; System.String swrString3 = null; System.String swrString4 = null; char[] chArr1 = { 'H', 'i' }; int iResult = 0; int[] iArrInvalidValues = new Int32[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, Int32.MinValue }; int[] iArrLargeValues = new Int32[] { Int32.MaxValue, Int32.MaxValue - 1, Int32.MaxValue / 2, Int32.MaxValue / 10, Int32.MaxValue / 100, 100000, 10000, 1000, 100, 21 }; int[] iArrValidValues = new Int32[] { 100000, 99999, 10000, 1000, 100, 10, 3 }; IntlStrings intl = new IntlStrings(); String intlString = intl.GetString(20, true, true); String str1 = intlString.Substring(5, 5); iCountTestcases++; for (int iLoop = 0; iLoop < iArrInvalidValues.Length; iLoop++) { try { iResult = str1.LastIndexOfAny(chArr1, iArrInvalidValues[iLoop]); iCountErrors++; Console.WriteLine("Error_0000!!! Expected exception not occured..."); } catch (ArgumentOutOfRangeException) { } catch (Exception ex) { Console.WriteLine("Error_2222!!! Unexpected exception " + ex.ToString()); iCountErrors++; } } iCountTestcases++; for (int iLoop = 0; iLoop < iArrLargeValues.Length; iLoop++) { try { iResult = intlString.LastIndexOfAny(chArr1, iArrLargeValues[iLoop]); iCountErrors++; Console.WriteLine("Error_1111!!! Expected exception not occured..."); } catch (ArgumentOutOfRangeException) { } catch (Exception ex) { Console.WriteLine("Error_3333!!! Unexpected exception " + ex.ToString()); iCountErrors++; } } iCountTestcases++; intlString = intl.GetString(100002, true, true); chArr1 = intlString.Substring(0, 2).ToCharArray(); for (int iLoop = 0; iLoop < iArrValidValues.Length; iLoop++) { try { iResult = intlString.LastIndexOfAny(chArr1, iArrValidValues[iLoop]); if (iResult == -1) { iCountErrors++; Console.WriteLine("Error_6666!!!! Incorrect LastIndexOfAny value.... Actual...{0}", iResult); } } catch (Exception ex) { Console.WriteLine("Error_7777!!! Unexpected exception " + ex.ToString()); iCountErrors++; } } char[] cArr = { 'i' }; char[] cArr1 = { 'H', 'i' }; swrString2 = "abc X def X ghi"; n2 = swrString2.LastIndexOfAny(cArr, 13); if (n2 != -1) { iCountErrors = iCountErrors | 0x1; } try { n2 = swrString2.LastIndexOfAny(cArr, -1); iCountErrors = iCountErrors | 0x2; } catch (ArgumentException) { } catch (Exception) { iCountErrors = iCountErrors | 0x40; } cArr[0] = 'c'; n2 = swrString2.LastIndexOfAny(cArr, 3); if (n2 != 2) { iCountErrors = iCountErrors | 0x4; } cArr[0] = 'X'; n2 = swrString2.LastIndexOfAny(cArr, 7); if (n2 != 4) { iCountErrors = iCountErrors | 0x8; } n2 = swrString2.LastIndexOfAny(cArr1, 12); if (n2 != -1) { iCountErrors = iCountErrors | 0x40; } n2 = swrString2.LastIndexOfAny(cArr1, 13); if (n2 != -1) { iCountErrors = iCountErrors | 0x80; } intl = new IntlStrings(); swrString2 = intl.GetString(4, true, true); swrString3 = intl.GetString(1, true, true); swrString4 = String.Concat(swrString2, swrString3); swrString4 = String.Concat(swrString4, swrString2); swrString4 = String.Concat(swrString4, swrString3); swrString4 = String.Concat(swrString4, swrString2); n2 = swrString4.LastIndexOfAny(swrString2.ToCharArray(), 7); if (n2 < 7) { iCountErrors = iCountErrors | 0x100; } System.Console.Error.Write("String.LastIndexOfAny: Co1161LIO iCountErrors=="); System.Console.Error.WriteLine(iCountErrors); if (iCountErrors == 0) { return(true); } else { return(false); } }
private String Validate(String value) { if (value == null || value.Length == 0) return value; Char[] validateChar = {(Char)0xD, (Char)0x9}; int index = value.LastIndexOfAny(validateChar); if (index > -1) throw new RemotingException(Environment.GetResourceString("Remoting_SOAPInteropxsdInvalid", "xsd:token", value)); if (value.Length > 0) { if (Char.IsWhiteSpace(value[0]) || Char.IsWhiteSpace(value[value.Length - 1])) throw new RemotingException(Environment.GetResourceString("Remoting_SOAPInteropxsdInvalid", "xsd:token", value)); } index = value.IndexOf(" "); if (index > -1) throw new RemotingException(Environment.GetResourceString("Remoting_SOAPInteropxsdInvalid", "xsd:token", value)); return value; }
private String Validate(String value) { if (value == null || value.Length == 0) return value; Char[] validateChar = {(Char)0xD, (Char)0xA, (Char)0x9}; int index = value.LastIndexOfAny(validateChar); if (index > -1) throw new RemotingException(Environment.GetResourceString("Remoting_SOAPInteropxsdInvalid", "xsd:normalizedString", value)); return value; }
/// <summary> /// Parse a rfc 2822 date and time specification. rfc 2822 section 3.3 /// </summary> /// <param name="date">rfc 2822 date-time</param> /// <returns>A <see cref="System.DateTime" /> from the parsed header body</returns> public static DateTime parseDate(String date) { if (date == null || date.Equals(String.Empty)) return DateTime.MinValue; DateTime msgDateTime = new DateTime(0); date = anmar.SharpMimeTools.SharpMimeTools.uncommentString(date); try { // TODO: Complete the list date = date.Replace("UT", "+0000"); date = date.Replace("GMT", "+0000"); date = date.Replace("EDT", "-0400"); date = date.Replace("EST", "-0500"); date = date.Replace("CDT", "-0500"); date = date.Replace("MDT", "-0600"); date = date.Replace("MST", "-0600"); date = date.Replace("EST", "-0700"); date = date.Replace("PDT", "-0700"); date = date.Replace("PST", "-0800"); date = date.Replace("AM", String.Empty); date = date.Replace("PM", String.Empty); int rpos = date.LastIndexOfAny(new Char[] { ' ', '\t' }); if (rpos > 0 && rpos != date.Length - 6) date = date.Substring(0, rpos + 1) + "-0000"; date = date.Insert(date.Length - 2, ":"); msgDateTime = DateTime.ParseExact(date, _date_formats, System.Globalization.CultureInfo.CreateSpecificCulture("en-us"), System.Globalization.DateTimeStyles.AllowInnerWhite); } catch (Exception) { msgDateTime = new DateTime(0); } return msgDateTime; }
private static void CheckForSpecialCharHelper(String typeName, int endIndex) { int originalEnd = endIndex; char[] specialChars = { ',', '[', ']', '+', '\\' }; while (endIndex >= 0) { endIndex = typeName.LastIndexOfAny(specialChars, endIndex); if (endIndex == -1) return; bool evenSlashes = true; if ((typeName[endIndex] == '\\') && (endIndex != originalEnd)) { char nextChar = typeName[endIndex+1]; if ((nextChar == '+') || (nextChar == '[') || (nextChar == ']') || (nextChar == '&') || (nextChar == '*') || (nextChar == ',')) evenSlashes = false; } while ((--endIndex >= 0) && typeName[endIndex] == '\\') evenSlashes = !evenSlashes; // Even number of slashes means this is a lone special char if (evenSlashes) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidTypeName")); } }
internal static String PathEnd(String path) { path = path.TrimEnd(anySlash); int i = path.LastIndexOfAny(anySlash); if (i >= 0) path = path.Substring(i + 1); return path; }
public static String strip_path(String str) { int pos = Math.Max(0, str.LastIndexOfAny(path_sep)); return str.Substring(pos); }