/// <summary> Parses the upgrade types.</summary> public static ArrayList getUpgradeTypes(System.String techData) { ArrayList types = new ArrayList(); String[] typs = techData.Split(':'); bool first = true; foreach(String typ in typs) { if (first) { first = false; continue; } System.String[] attribtes = typ.Split(";".ToCharArray()); UpgradeType type = new UpgradeType { ID = System.Int32.Parse(attribtes[0]), Name = attribtes[1], WhatResearchesID = System.Int32.Parse(attribtes[2]), Repeats = System.Int32.Parse(attribtes[3]), MineralsBase = System.Int32.Parse(attribtes[4]), MineralsFactor = System.Int32.Parse(attribtes[5]), GasBase = System.Int32.Parse(attribtes[6]), GasFactor = System.Int32.Parse(attribtes[7]) }; types.Add(type); } return types; }
public void Split_IfFractionInFirstNotBetween0And1_Throw(double bad) { var list = new[] {1, 2, 3, 4}; Action action = () => list.Split(bad); action.ShouldThrow<ArgumentOutOfRangeException>() .WithMessage($"*Argument fractionInFirst must be between 0 and 1; was {bad}.*") .Where(e => ((double) e.ActualValue) == bad || double.IsNaN(((double)e.ActualValue))); }
public bool HasSystem(string systemID) { if (systemID == System) { return(true); } return(System.Split('_').Contains(systemID)); }
public void TestSplit() { Assert.Throws<ArgumentNullException>(() => { IEnumerableExtensions.Split<string>(null, null); }); Assert.Throws<ArgumentNullException>(() => { IEnumerableExtensions.Split<string>(new string[0], null); }); Assert.Throws<ArgumentNullException>(() => { IEnumerableExtensions.Split<string>(null, str => str != null); }); var input = new[] { 1, 47, 4, 47, 5, 6, 1, 47, 47, 47, 0 }; var result = input.Split(i => i == 47).ToArray(); Assert.AreEqual(6, result.Length); Assert.That(result[0].SequenceEqual(new[] { 1 })); Assert.That(result[1].SequenceEqual(new[] { 4 })); Assert.That(result[2].SequenceEqual(new[] { 5, 6, 1 })); Assert.That(result[3].SequenceEqual(new int[] { })); Assert.That(result[4].SequenceEqual(new int[] { })); Assert.That(result[5].SequenceEqual(new[] { 0 })); }
public MetaInfo(System.String Data) { System.String[] Lines = Data.Split(new System.Char[] { '\n' }); foreach (System.String Line in Lines) { System.String[] Opts = Line.Split(new System.Char[] { '=' }); switch (Opts[0].ToLower()) { case "station": this._Station = Opts[1]; break; case "artist": this._Artist = Opts[1]; break; case "track": this._Track = Opts[1]; break; case "album": this._Album = Opts[1]; break; case "albumcover_small": this._AlbumcoverSmall = Opts[1]; break; case "albumcover_medium": this._AlbumcoverMedium = Opts[1]; break; case "albumcover_large": this._AlbumcoverLarge = Opts[1]; break; case "trackduration": this._Trackduration = Opts[1]; break; case "trackprogress": this._Trackprogress = Opts[1]; break; case "streaming": if (Opts[1].ToLower() == "false") { } break; } } }
/// <param name="ipAndMaskBits"> /// </param> /// <returns> /// </returns> public static System.String ExtractIp(System.String ipRange) { if (IsRangeWithMaskBits(ipRange)) { Match m = Regex.Match(ipRange, REGEX_IP_AND_MASK_BITS); if (m.Success) { return m.Groups[1].Value; } throw new System.Exception("IpUtil.ExtractIp(): bad IP format: " + ipRange); } else if (IsRangeWithDottedMask(ipRange)) { return ipRange.Split(new char[]{' '})[0]; } else { throw new System.Exception("IpUtil.ExtractIp(): bad IP format: " + ipRange); } }
/// <summary> Creates a map based on the string recieved from the AIModule. /// /// </summary> /// <param name="mapData">- mapname:width:height:data /// /// Data is a character array where each tile is represented by 3 characters, /// which specific height, buildable, walkable. /// </param> public MapData(System.String mapData) { System.String[] map = mapData.Split(":".ToCharArray()); System.String data = map[3]; mapName = map[0]; mapWidth = System.Int32.Parse(map[1]); mapHeight = System.Int32.Parse(map[2]); height = new int[mapHeight][]; for (int i = 0; i < mapHeight; i++) { height[i] = new int[mapWidth]; } buildable = new bool[mapHeight][]; for (int i2 = 0; i2 < mapHeight; i2++) { buildable[i2] = new bool[mapWidth]; } walkable = new bool[mapHeight][]; for (int i3 = 0; i3 < mapHeight; i3++) { walkable[i3] = new bool[mapWidth]; } int total = mapWidth * mapHeight; for (int i = 0; i < total; i++) { int w = i % mapWidth; int h = i / mapWidth; System.String tile = data.Substring(3 * i, (3 * i + 3) - (3 * i)); height[h][w] = System.Int32.Parse(tile.Substring(0, (1) - (0))); buildable[h][w] = (1 == System.Int32.Parse(tile.Substring(1, (2) - (1)))); walkable[h][w] = (1 == System.Int32.Parse(tile.Substring(2, (3) - (2)))); } }
/// <param name="ipAndMaskBits"> /// </param> /// <returns> /// </returns> public static int ExtractMaskBits(System.String ipRange) { if (IsRangeWithMaskBits(ipRange)) { Match m = Regex.Match(ipRange, REGEX_IP_AND_MASK_BITS); if (m.Success) { return int.Parse( m.Groups[2].Value ); } throw new System.Exception("IpUtil.ExtractMaskBits(): bad IP format: " + ipRange); } else if (IsRangeWithDottedMask(ipRange)) { System.String mask = ipRange.Split(new char[]{' '})[1]; return MaskToBits(mask); } else { throw new System.Exception("IpUtil.ExtractMaskBits(): bad IP format: " + ipRange); } }
public static bool IsRangeWithDottedMask(System.String range) { return (range.IndexOf(" ")!=-1 && IsIP(range.Split(new char[]{' '})[0]) && IsIP(range.Split(new char[]{' '})[1])); }
public void Split_GroupSizeIsNotMultipleOfSourceCount_LastGroupHasSmallerSize() { var source = new[] { 1, 2, 3, 4, 5, 6, 7 }; var result = source.Split(source.Length / 2).ToList(); Assert.That(result.Count, Is.EqualTo(3)); CollectionAssert.AreEqual(result[0], source.Take(3)); CollectionAssert.AreEqual(result[1], source.Skip(3).Take(3)); CollectionAssert.AreEqual(result[2], source.Skip(6).Take(3)); CollectionAssert.AreEqual(result.SelectMany(group => group.ToList()), source); }
/// <summary> Parses a line of data, and sets the prepared statement with the /// values. If a token contains "<null>" then a null value is passed /// in. /// /// </summary> /// <param name="data">the tokenized string that is mapped to a row /// </param> /// <param name="stmt">the statement to populate with data to be inserted /// </param> /// <returns> false if the header is returned, true otherwise /// </returns> /// <throws> SQLException if an error occurs while inserting data into the database </throws> protected internal override bool insert(System.String data, System.Data.Common.DbCommand stmt) { if (!parsedHeader) { parsedHeader = true; log.Info("Header returned: " + data); return false; } int counter = 1; log.Info("Row being parsed: " + data); stmt.Parameters.Clear(); foreach (string colVal in data.Split(Delimiter)) { System.Data.Common.DbParameter parameter = stmt.CreateParameter(); parameter.ParameterName = PARAMETER_NAME_PREFIX + counter.ToString(); if (colVal.ToLower().Equals("<null>")) { parameter.Value = DBNull.Value; } else { parameter.Value = colVal; } stmt.Parameters.Add(parameter); counter++; } return true; }
public bool HasSystem(string systemID) { return(systemID == System || System.Split('_').Contains(systemID)); }
public void Split_GroupSizeIsMultipleOfSourceCount_ReturnsGroupsOfSameSize() { var source = new [] { 1, 2, 3, 4, 5, 6 }; var result = source.Split(source.Length / 2).ToList(); Assert.That(result.Count, Is.EqualTo(2)); CollectionAssert.AreEqual(result[0], source.Take(3)); CollectionAssert.AreEqual(result[1], source.Skip(3).Take(3)); CollectionAssert.AreEqual(result.SelectMany(group => group.ToList()), source); }
/// <summary> /// Convert from DICOM format to Common Data Format. /// </summary> /// <param name="dicomFormat">DICOM format.</param> public override void FromDicomFormat(System.String dicomFormat) { // remove any trailing spaces from the name dicomFormat = dicomFormat.TrimEnd(' '); // split the incoming dicom format into the three component groups System.String[] nameComponentGroups = new System.String[3]; nameComponentGroups = dicomFormat.Split('='); // split the first component group into the five components if (nameComponentGroups.Length > 0) { System.String[] nameComponents = new System.String[5]; nameComponents = nameComponentGroups[0].Split('^'); // save the individual components switch(nameComponents.Length) { case 1: _surname = nameComponents[0]; break; case 2: _surname = nameComponents[0]; _firstName = nameComponents[1]; break; case 3: _surname = nameComponents[0]; _firstName = nameComponents[1]; _middleName = nameComponents[2]; break; case 4: _surname = nameComponents[0]; _firstName = nameComponents[1]; _middleName = nameComponents[2]; _prefix = nameComponents[3]; break; case 5: _surname = nameComponents[0]; _firstName = nameComponents[1]; _middleName = nameComponents[2]; _prefix = nameComponents[3]; _suffix = nameComponents[4]; break; default: break; } // save the ideographic name - if present if (nameComponentGroups.Length > 1) { _ideographicName = nameComponentGroups[1]; } // save the phonetic name - if present if (nameComponentGroups.Length > 2) { _phoneticName = nameComponentGroups[2]; } } }
/// <summary> /// Parse a rfc 2822 header field with parameters /// </summary> /// <param name="field">field name</param> /// <param name="fieldbody">field body to parse</param> /// <returns>A <see cref="System.Collections.Specialized.StringDictionary" /> from the parsed field body</returns> public static System.Collections.Specialized.StringDictionary parseHeaderFieldBody( System.String field, System.String fieldbody ) { if ( fieldbody==null ) return null; // FIXME: rewrite parseHeaderFieldBody to being regexp based. fieldbody = anmar.SharpMimeTools.SharpMimeTools.uncommentString (fieldbody); System.Collections.Specialized.StringDictionary fieldbodycol = new System.Collections.Specialized.StringDictionary (); System.String[] words = fieldbody.Split(new Char[]{';'}); if ( words.Length>0 ) { fieldbodycol.Add (field.ToLower(), words[0].ToLower()); for (int i=1; i<words.Length; i++ ) { System.String[] param = words[i].Trim(new Char[]{' ', '\t'}).Split(new Char[]{'='}, 2); if ( param.Length==2 ) { param[0] = param[0].Trim(new Char[]{' ', '\t'}); param[1] = param[1].Trim(new Char[]{' ', '\t'}); if ( param[1].StartsWith("\"") && !param[1].EndsWith("\"")) { do { param[1] += ";" + words[++i]; } while ( !words[i].EndsWith("\"") && i<words.Length); } fieldbodycol.Add ( param[0], anmar.SharpMimeTools.SharpMimeTools.parserfc2047Header (param[1].TrimEnd(';').Trim('\"')) ); } } } return fieldbodycol; }
public void Split_GroupSizeIsSameAsSourceCount_ReturnsSingleGroupSameAsSource() { var source = new [] { 1, 2, 3 }; var result = source.Split(source.Length).ToList(); Assert.That(result.Count, Is.EqualTo(1)); CollectionAssert.AreEqual(result[0], source); }
internal bool IsSystem(string systemID) { return(systemID == System || System.Split('_').Contains(systemID)); }
//From: http://www.ip2location.com/README-IP-COUNTRY.htm /// <param name="dottedIP"> /// </param> /// <returns> /// </returns> public static long ipToLong(System.String dottedIP) { int i; System.String[] arrDec; double num = 0; if ((System.Object) dottedIP == (System.Object) "") { return 0; } else { arrDec = dottedIP.Split(new char[] { '.' }); for (i = arrDec.Length - 1; i >= 0; i--) { num += ((System.Int64.Parse(arrDec[i]) % 256) * System.Math.Pow(256, (3 - i))); } //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" return (long) num; } }
/// <summary> /// Parse login data from a request /// </summary> /// <param name="Data">Data from the request</param> protected virtual void ParseLogin(System.String Data) { try { //Did this request go well? System.Boolean Result = false; //Subscriber System.Boolean Subscriber = false; foreach(System.String Line in Data.Split(new System.Char[]{'\n'})) { System.String[] Opts = Line.Split(new System.Char[]{'='}); //Skip this line if it's bad if(Opts.Length != 2) continue; switch(Opts[0].ToLower()) { case "session": if(Opts[1].ToLower() == "failed") { Result = false; }else{ Result = true; this.SessionID = Opts[1]; this._Connected = true; } break; case "stream_url": //Ignore this attribute, it obsolete break; case "subscriber": if(Opts[1] == "1") { Subscriber = true; }else{ Subscriber = false; } break; case "framehack": //Don't know what this is for, ignoring it break; case "base_url": this.BaseURL = Opts[1]; break; case "base_path": this.BasePath = Opts[1]; break; default: Console.WriteLine("nScrobbler.ParseLogin() Unknown key: " + Opts[0] + " Value: " + Opts[1]); break; } } //Raise event if anybody is subscribted to it if(this.CommandReturn != null) { CommandEventArgs Args = new LoginCommandEventArgs(Result, Subscriber); this.CommandReturn(this, Args); } } catch(System.Exception e) { //Raise event if anybody is subscribted to it if(this.CommandReturn != null) { //Warp the exception nicely System.Exception Exception = new System.Exception("Exception while parsing login data", e); //Return the command with the exception this.CommandReturn(this, new LoginCommandEventArgs(false, false, Exception)); } } }
/// <summary> /// Convert from HL7 format to Common Data Format. /// </summary> /// <param name="hl7Format">HL7 format.</param> public override void FromHl7Format(System.String hl7Format) { // <family name (ST)> ^ // <given name (ST)> ^ // <middle initial or name (ST)> ^ // <suffix (e.g., JR or III) (ST)> ^ // <prefix (e.g., DR) (ST)> ^ // <degree (e.g., MD) (ST)> // remove any trailing spaces from the name hl7Format = hl7Format.TrimEnd(' '); // split the HL7 format into the six components System.String[] nameComponents = new System.String[6]; nameComponents = hl7Format.Split('^'); // save the individual components switch(nameComponents.Length) { case 1: _surname = nameComponents[0]; break; case 2: _surname = nameComponents[0]; _firstName = nameComponents[1]; break; case 3: _surname = nameComponents[0]; _firstName = nameComponents[1]; _middleName = nameComponents[2]; break; case 4: _surname = nameComponents[0]; _firstName = nameComponents[1]; _middleName = nameComponents[2]; _suffix = nameComponents[3]; break; case 5: _surname = nameComponents[0]; _firstName = nameComponents[1]; _middleName = nameComponents[2]; _suffix = nameComponents[3]; _prefix = nameComponents[4]; break; case 6: _surname = nameComponents[0]; _firstName = nameComponents[1]; _middleName = nameComponents[2]; _suffix = nameComponents[3]; _prefix = nameComponents[4]; _degree = nameComponents[5]; break; default: break; } }
/// <summary> Parses the unit types.</summary> //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'" public static Dictionary<int, UnitType> getUnitTypes(System.String unitTypeData) { //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'" Dictionary<int, UnitType> types = new Dictionary<int, UnitType>(); System.String[] unitTypes = unitTypeData.Split(":".ToCharArray()); bool first = true; foreach(String unitType in unitTypes) { if (first) { first = false; continue; } System.String[] attributes = unitType.Split(";".ToCharArray()); UnitType type = new UnitType { ID = System.Int32.Parse(attributes[0]), Race = attributes[1], Name = attributes[2], MineralsCost = System.Int32.Parse(attributes[3]), GasCost = System.Int32.Parse(attributes[4]), MaxHitPoints = System.Int32.Parse(attributes[5]), MaxShields = System.Int32.Parse(attributes[6]), MaxEnergy = System.Int32.Parse(attributes[7]), BuildTime = System.Int32.Parse(attributes[8]), CanAttack = System.Int32.Parse(attributes[9]) == 1, CanMove = System.Int32.Parse(attributes[10]) == 1, TileWidth = System.Int32.Parse(attributes[11]), TileHeight = System.Int32.Parse(attributes[12]), SupplyRequired = System.Int32.Parse(attributes[13]), SupplyProvided = System.Int32.Parse(attributes[14]), SightRange = System.Int32.Parse(attributes[15]), GroundMaxRange = System.Int32.Parse(attributes[16]), GroundMinRange = System.Int32.Parse(attributes[17]), GroundDamage = System.Int32.Parse(attributes[18]), AirRange = System.Int32.Parse(attributes[19]), AirDamage = System.Int32.Parse(attributes[20]), Building = System.Int32.Parse(attributes[21]) == 1, Flyer = System.Int32.Parse(attributes[22]) == 1, SpellCaster = System.Int32.Parse(attributes[23]) == 1, Worker = System.Int32.Parse(attributes[24]) == 1, WhatBuilds = System.Int32.Parse(attributes[25]), }; System.Console.Out.WriteLine(type.ID + " " + type.WhatBuilds); types.Add(type.ID, type); } return types; }