private Property Create() { var propertyInfo = typeof(DummyData).GetProperty("Int32"); var propertyAccess = new NumberConverter(); return new Property(propertyInfo, propertyAccess); }
public void run() { while (true) { Console.Write("Input: "); var s = Console.ReadLine(); try { _numberConverter = new NumberConverter(s); Console.WriteLine("Result: \"" + _numberConverter.GetNumberToWord()+"\""); }catch(Exception e) { Console.WriteLine("Result: \"Not Suported\"" ); } } }
public void WriteInt64(long value) { offset += NumberConverter.WriteInt64(ref buffer, offset, value); }
static DecoderTestCase ReadTestCase(int bitness, string line, int lineNumber) { var parts = line.Split(seps); if (parts.Length != 5) { throw new InvalidOperationException($"Invalid number of commas ({parts.Length - 1} commas)"); } var tc = new DecoderTestCase(); tc.LineNumber = lineNumber; tc.CanEncode = true; tc.Bitness = bitness; tc.HexBytes = ToHexBytes(parts[0].Trim()); tc.EncodedHexBytes = tc.HexBytes; tc.Code = ToCode(parts[1].Trim()); tc.Mnemonic = ToMnemonic(parts[2].Trim()); tc.OpCount = NumberConverter.ToInt32(parts[3].Trim()); foreach (var tmp in parts[4].Split(extraSeps)) { if (tmp == string.Empty) { continue; } var key = tmp; string value; int index = key.IndexOf('='); if (index >= 0) { value = key.Substring(index + 1); key = key.Substring(0, index); } else { value = null; } switch (key) { case DecoderTestParserConstants.NoEncode: tc.CanEncode = false; break; case DecoderTestParserConstants.InvalidNoMoreBytes: tc.InvalidNoMoreBytes = true; break; case DecoderTestParserConstants.Broadcast: tc.IsBroadcast = true; break; case DecoderTestParserConstants.Xacquire: tc.HasXacquirePrefix = true; break; case DecoderTestParserConstants.Xrelease: tc.HasXreleasePrefix = true; break; case DecoderTestParserConstants.Rep: case DecoderTestParserConstants.Repe: tc.HasRepePrefix = true; break; case DecoderTestParserConstants.Repne: tc.HasRepnePrefix = true; break; case DecoderTestParserConstants.Lock: tc.HasLockPrefix = true; break; case DecoderTestParserConstants.ZeroingMasking: tc.ZeroingMasking = true; break; case DecoderTestParserConstants.SuppressAllExceptions: tc.SuppressAllExceptions = true; break; case DecoderTestParserConstants.Vsib32: tc.VsibBitness = 32; break; case DecoderTestParserConstants.Vsib64: tc.VsibBitness = 64; break; case DecoderTestParserConstants.RoundToNearest: tc.RoundingControl = RoundingControl.RoundToNearest; break; case DecoderTestParserConstants.RoundDown: tc.RoundingControl = RoundingControl.RoundDown; break; case DecoderTestParserConstants.RoundUp: tc.RoundingControl = RoundingControl.RoundUp; break; case DecoderTestParserConstants.RoundTowardZero: tc.RoundingControl = RoundingControl.RoundTowardZero; break; case DecoderTestParserConstants.Op0Kind: if (tc.OpCount < 1) { throw new InvalidOperationException($"Invalid OpCount: {tc.OpCount} < 1"); } ReadOpKind(tc, 0, value); break; case DecoderTestParserConstants.Op1Kind: if (tc.OpCount < 2) { throw new InvalidOperationException($"Invalid OpCount: {tc.OpCount} < 2"); } ReadOpKind(tc, 1, value); break; case DecoderTestParserConstants.Op2Kind: if (tc.OpCount < 3) { throw new InvalidOperationException($"Invalid OpCount: {tc.OpCount} < 3"); } ReadOpKind(tc, 2, value); break; case DecoderTestParserConstants.Op3Kind: if (tc.OpCount < 4) { throw new InvalidOperationException($"Invalid OpCount: {tc.OpCount} < 4"); } ReadOpKind(tc, 3, value); break; case DecoderTestParserConstants.Op4Kind: if (tc.OpCount < 5) { throw new InvalidOperationException($"Invalid OpCount: {tc.OpCount} < 5"); } ReadOpKind(tc, 4, value); break; case DecoderTestParserConstants.EncodedHexBytes: if (string.IsNullOrWhiteSpace(value)) { throw new InvalidOperationException($"Invalid encoded hex bytes: '{value}'"); } tc.EncodedHexBytes = ToHexBytes(value); break; case DecoderTestParserConstants.DecoderOptions_AmdBranches: tc.DecoderOptions |= DecoderOptions.AmdBranches; break; case DecoderTestParserConstants.DecoderOptions_ForceReservedNop: tc.DecoderOptions |= DecoderOptions.ForceReservedNop; break; case DecoderTestParserConstants.DecoderOptions_Umov: tc.DecoderOptions |= DecoderOptions.Umov; break; case DecoderTestParserConstants.DecoderOptions_Xbts: tc.DecoderOptions |= DecoderOptions.Xbts; break; case DecoderTestParserConstants.DecoderOptions_Cmpxchg486A: tc.DecoderOptions |= DecoderOptions.Cmpxchg486A; break; case DecoderTestParserConstants.DecoderOptions_OldFpu: tc.DecoderOptions |= DecoderOptions.OldFpu; break; case DecoderTestParserConstants.DecoderOptions_Pcommit: tc.DecoderOptions |= DecoderOptions.Pcommit; break; case DecoderTestParserConstants.DecoderOptions_Loadall286: tc.DecoderOptions |= DecoderOptions.Loadall286; break; case DecoderTestParserConstants.DecoderOptions_Loadall386: tc.DecoderOptions |= DecoderOptions.Loadall386; break; case DecoderTestParserConstants.DecoderOptions_Cl1invmb: tc.DecoderOptions |= DecoderOptions.Cl1invmb; break; case DecoderTestParserConstants.DecoderOptions_MovTr: tc.DecoderOptions |= DecoderOptions.MovTr; break; case DecoderTestParserConstants.DecoderOptions_Jmpe: tc.DecoderOptions |= DecoderOptions.Jmpe; break; case DecoderTestParserConstants.DecoderOptions_NoPause: tc.DecoderOptions |= DecoderOptions.NoPause; break; case DecoderTestParserConstants.DecoderOptions_NoWbnoinvd: tc.DecoderOptions |= DecoderOptions.NoWbnoinvd; break; case DecoderTestParserConstants.DecoderOptions_NoLockMovCR0: tc.DecoderOptions |= DecoderOptions.NoLockMovCR0; break; case DecoderTestParserConstants.DecoderOptions_NoMPFX_0FBC: tc.DecoderOptions |= DecoderOptions.NoMPFX_0FBC; break; case DecoderTestParserConstants.DecoderOptions_NoMPFX_0FBD: tc.DecoderOptions |= DecoderOptions.NoMPFX_0FBD; break; case DecoderTestParserConstants.DecoderOptions_NoLahfSahf64: tc.DecoderOptions |= DecoderOptions.NoLahfSahf64; break; case DecoderTestParserConstants.DecoderOptions_NoInvalidCheck: tc.DecoderOptions |= DecoderOptions.NoInvalidCheck; break; case DecoderTestParserConstants.SegmentPrefix_ES: tc.SegmentPrefix = Register.ES; break; case DecoderTestParserConstants.SegmentPrefix_CS: tc.SegmentPrefix = Register.CS; break; case DecoderTestParserConstants.SegmentPrefix_SS: tc.SegmentPrefix = Register.SS; break; case DecoderTestParserConstants.SegmentPrefix_DS: tc.SegmentPrefix = Register.DS; break; case DecoderTestParserConstants.SegmentPrefix_FS: tc.SegmentPrefix = Register.FS; break; case DecoderTestParserConstants.SegmentPrefix_GS: tc.SegmentPrefix = Register.GS; break; case DecoderTestParserConstants.OpMask_k1: tc.OpMask = Register.K1; break; case DecoderTestParserConstants.OpMask_k2: tc.OpMask = Register.K2; break; case DecoderTestParserConstants.OpMask_k3: tc.OpMask = Register.K3; break; case DecoderTestParserConstants.OpMask_k4: tc.OpMask = Register.K4; break; case DecoderTestParserConstants.OpMask_k5: tc.OpMask = Register.K5; break; case DecoderTestParserConstants.OpMask_k6: tc.OpMask = Register.K6; break; case DecoderTestParserConstants.OpMask_k7: tc.OpMask = Register.K7; break; case DecoderTestParserConstants.ConstantOffsets: if (!TryParseConstantOffsets(value, out tc.ConstantOffsets)) { throw new InvalidOperationException($"Invalid ConstantOffsets: '{value}'"); } break; default: throw new InvalidOperationException($"Invalid key '{key}'"); } } return(tc); }
private IBucket GetKeyedBucket(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { var token = reader.GetCurrentJsonToken(); if (token == JsonToken.BeginObject) { return(GetCompositeBucket(ref reader, formatterResolver)); } object key; if (token == JsonToken.String) { key = reader.ReadString(); } else { var numberSegment = reader.ReadNumberSegment(); if (numberSegment.IsLong()) { key = NumberConverter.ReadInt64(numberSegment.Array, numberSegment.Offset, out _); } else { key = NumberConverter.ReadDouble(numberSegment.Array, numberSegment.Offset, out _); } } reader.ReadNext(); // , var propertyName = reader.ReadPropertyName(); if (propertyName == Parser.From || propertyName == Parser.To) { var rangeKey = key is double d ? d.ToString("#.#") : key.ToString(); return(GetRangeBucket(ref reader, formatterResolver, rangeKey, propertyName)); } string keyAsString = null; if (propertyName == Parser.KeyAsString) { keyAsString = reader.ReadString(); reader.ReadNext(); // , reader.ReadNext(); // "doc_count" reader.ReadNext(); // : } var docCount = reader.ReadInt64(); Dictionary <string, IAggregate> subAggregates = null; long?docCountErrorUpperBound = null; token = reader.GetCurrentJsonToken(); if (token == JsonToken.ValueSeparator) { reader.ReadNext(); propertyName = reader.ReadPropertyName(); switch (propertyName) { case Parser.Score: return(GetSignificantTermsBucket(ref reader, formatterResolver, key, docCount)); case Parser.DocCountErrorUpperBound: { docCountErrorUpperBound = reader.ReadNullableLong(); token = reader.GetCurrentJsonToken(); if (token == JsonToken.ValueSeparator) { reader.ReadNext(); // , propertyName = reader.ReadPropertyName(); subAggregates = GetSubAggregates(ref reader, propertyName, formatterResolver); } break; } default: subAggregates = GetSubAggregates(ref reader, propertyName, formatterResolver); break; } } return(new KeyedBucket <object>(subAggregates) { Key = key, KeyAsString = keyAsString, DocCount = docCount, DocCountErrorUpperBound = docCountErrorUpperBound }); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return(NumberConverter.ByteToFitString((long)value)); }
public DateTimeOffset Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { var str = reader.ReadStringSegmentUnsafe(); var array = str.Array; var i = str.Offset; var len = str.Count; var to = str.Offset + str.Count; // YYYY if (len == 4) { var y = (array[i++] - (byte)'0') * 1000 + (array[i++] - (byte)'0') * 100 + (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); return(new DateTimeOffset(y, 1, 1, 0, 0, 0, TimeSpan.Zero)); } // YYYY-MM if (len == 7) { var y = (array[i++] - (byte)'0') * 1000 + (array[i++] - (byte)'0') * 100 + (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'-') { goto ERROR; } var m = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); return(new DateTimeOffset(y, m, 1, 0, 0, 0, TimeSpan.Zero)); } // YYYY-MM-DD if (len == 10) { var y = (array[i++] - (byte)'0') * 1000 + (array[i++] - (byte)'0') * 100 + (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'-') { goto ERROR; } var m = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'-') { goto ERROR; } var d = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); return(new DateTimeOffset(y, m, d, 0, 0, 0, TimeSpan.Zero)); } // range-first section requires 19 if (array.Length < 19) { goto ERROR; } var year = (array[i++] - (byte)'0') * 1000 + (array[i++] - (byte)'0') * 100 + (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'-') { goto ERROR; } var month = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'-') { goto ERROR; } var day = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'T') { goto ERROR; } var hour = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)':') { goto ERROR; } var minute = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)':') { goto ERROR; } var second = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); var ticks = 0; if (i < to && array[i] == '.') { i++; // *7. if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1000000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 100000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 10000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 100; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 10; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1; i++; // others, lack of precision while (i < to && NumberConverter.IsNumber(array[i])) { i++; } } END_TICKS: if (i < to && array[i] == '-' || array[i] == '+') { var offLen = to - i; if (offLen != 3 && offLen != 5 && offLen != 6) { goto ERROR; } var minus = array[i++] == '-'; var h = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); var m = 0; if (i < to) { if (offLen == 6) { if (array[i] != ':') { goto ERROR; } i++; } m = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); } var offset = new TimeSpan(h, m, 0); if (minus) { offset = offset.Negate(); } return(new DateTimeOffset(year, month, day, hour, minute, second, offset).AddTicks(ticks)); } return(new DateTimeOffset(year, month, day, hour, minute, second, TimeSpan.Zero).AddTicks(ticks)); ERROR: throw new InvalidOperationException("invalid datetime format. value:" + StringEncoding.UTF8.GetString(str.Array, str.Offset, str.Count)); }
public void Convert() { if (bc.IsValidRadix(mInputBase) && bc.IsValidRadix(mOutputBase)) { if (bc.IsValidString(InputString, mInputBase)) { try { InputNumber = NumberConverter.ToBase(InputString, mInputBase, mInputBase); OutputNumber = NumberConverter.ToBase(InputNumber.DecimalValue, mOutputBase); mHistory.AddEntry(InputNumber, OutputNumber); InputString = InputNumber.ValueInBase; OutputString = OutputNumber.ValueInBase; ErrorMessage = ""; } catch (System.OverflowException) { ErrorMessage = "The input number is to large. Max value in base " + InputBase + ": " + NumberConverter.MaxValueForBase(mInputBase); InputNumber = NumberConverter.ToBase(0, 10); OutputNumber = NumberConverter.ToBase(0, 10); InputString = InputNumber.ValueInBase; OutputString = OutputNumber.ValueInBase; } } else { ErrorMessage = "The number does not match it's given radix"; } } else { ErrorMessage = "Radix must be between 2 and 99"; } }
static void ReadOpKind(DecoderTestCase tc, int operand, string value) { var parts = value.Split(opKindSeps); switch (parts[0]) { case DecoderTestParserConstants.OpKind_Register: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpRegister(operand, ToRegister(parts[1])); tc.SetOpKind(operand, OpKind.Register); break; case DecoderTestParserConstants.OpKind_NearBranch16: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.NearBranch16); tc.NearBranch = NumberConverter.ToUInt16(parts[1]); break; case DecoderTestParserConstants.OpKind_NearBranch32: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.NearBranch32); tc.NearBranch = NumberConverter.ToUInt32(parts[1]); break; case DecoderTestParserConstants.OpKind_NearBranch64: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.NearBranch64); tc.NearBranch = NumberConverter.ToUInt64(parts[1]); break; case DecoderTestParserConstants.OpKind_FarBranch16: if (parts.Length != 3) { throw new InvalidOperationException($"Operand {operand}: expected 3 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.FarBranch16); tc.FarBranchSelector = NumberConverter.ToUInt16(parts[1]); tc.FarBranch = NumberConverter.ToUInt16(parts[2]); break; case DecoderTestParserConstants.OpKind_FarBranch32: if (parts.Length != 3) { throw new InvalidOperationException($"Operand {operand}: expected 3 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.FarBranch32); tc.FarBranchSelector = NumberConverter.ToUInt16(parts[1]); tc.FarBranch = NumberConverter.ToUInt32(parts[2]); break; case DecoderTestParserConstants.OpKind_Immediate8: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.Immediate8); tc.Immediate = NumberConverter.ToUInt8(parts[1]); break; case DecoderTestParserConstants.OpKind_Immediate16: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.Immediate16); tc.Immediate = NumberConverter.ToUInt16(parts[1]); break; case DecoderTestParserConstants.OpKind_Immediate32: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.Immediate32); tc.Immediate = NumberConverter.ToUInt32(parts[1]); break; case DecoderTestParserConstants.OpKind_Immediate64: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.Immediate64); tc.Immediate = NumberConverter.ToUInt64(parts[1]); break; case DecoderTestParserConstants.OpKind_Immediate8to16: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.Immediate8to16); tc.Immediate = NumberConverter.ToUInt16(parts[1]); break; case DecoderTestParserConstants.OpKind_Immediate8to32: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.Immediate8to32); tc.Immediate = NumberConverter.ToUInt32(parts[1]); break; case DecoderTestParserConstants.OpKind_Immediate8to64: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.Immediate8to64); tc.Immediate = NumberConverter.ToUInt64(parts[1]); break; case DecoderTestParserConstants.OpKind_Immediate32to64: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.Immediate32to64); tc.Immediate = NumberConverter.ToUInt64(parts[1]); break; case DecoderTestParserConstants.OpKind_Immediate8_2nd: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.Immediate8_2nd); tc.Immediate_2nd = NumberConverter.ToUInt8(parts[1]); break; case DecoderTestParserConstants.OpKind_MemorySegSI: if (parts.Length != 3) { throw new InvalidOperationException($"Operand {operand}: expected 3 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.MemorySegSI); tc.MemorySegment = ToRegister(parts[1]); tc.MemorySize = ToMemorySize(parts[2]); break; case DecoderTestParserConstants.OpKind_MemorySegESI: if (parts.Length != 3) { throw new InvalidOperationException($"Operand {operand}: expected 3 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.MemorySegESI); tc.MemorySegment = ToRegister(parts[1]); tc.MemorySize = ToMemorySize(parts[2]); break; case DecoderTestParserConstants.OpKind_MemorySegRSI: if (parts.Length != 3) { throw new InvalidOperationException($"Operand {operand}: expected 3 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.MemorySegRSI); tc.MemorySegment = ToRegister(parts[1]); tc.MemorySize = ToMemorySize(parts[2]); break; case DecoderTestParserConstants.OpKind_MemorySegDI: if (parts.Length != 3) { throw new InvalidOperationException($"Operand {operand}: expected 3 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.MemorySegDI); tc.MemorySegment = ToRegister(parts[1]); tc.MemorySize = ToMemorySize(parts[2]); break; case DecoderTestParserConstants.OpKind_MemorySegEDI: if (parts.Length != 3) { throw new InvalidOperationException($"Operand {operand}: expected 3 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.MemorySegEDI); tc.MemorySegment = ToRegister(parts[1]); tc.MemorySize = ToMemorySize(parts[2]); break; case DecoderTestParserConstants.OpKind_MemorySegRDI: if (parts.Length != 3) { throw new InvalidOperationException($"Operand {operand}: expected 3 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.MemorySegRDI); tc.MemorySegment = ToRegister(parts[1]); tc.MemorySize = ToMemorySize(parts[2]); break; case DecoderTestParserConstants.OpKind_MemoryESDI: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.MemoryESDI); tc.MemorySize = ToMemorySize(parts[1]); break; case DecoderTestParserConstants.OpKind_MemoryESEDI: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.MemoryESEDI); tc.MemorySize = ToMemorySize(parts[1]); break; case DecoderTestParserConstants.OpKind_MemoryESRDI: if (parts.Length != 2) { throw new InvalidOperationException($"Operand {operand}: expected 2 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.MemoryESRDI); tc.MemorySize = ToMemorySize(parts[1]); break; case DecoderTestParserConstants.OpKind_Memory64: if (parts.Length != 4) { throw new InvalidOperationException($"Operand {operand}: expected 4 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.Memory64); tc.MemorySegment = ToRegister(parts[1]); tc.MemoryAddress64 = NumberConverter.ToUInt64(parts[2]); tc.MemorySize = ToMemorySize(parts[3]); break; case DecoderTestParserConstants.OpKind_Memory: if (parts.Length != 8) { throw new InvalidOperationException($"Operand {operand}: expected 8 values, actual = {parts.Length}"); } tc.SetOpKind(operand, OpKind.Memory); tc.MemorySegment = ToRegister(parts[1]); tc.MemoryBase = ToRegister(parts[2]); tc.MemoryIndex = ToRegister(parts[3]); tc.MemoryIndexScale = NumberConverter.ToInt32(parts[4]); tc.MemoryDisplacement = NumberConverter.ToUInt32(parts[5]); tc.MemoryDisplSize = NumberConverter.ToInt32(parts[6]); tc.MemorySize = ToMemorySize(parts[7]); break; default: throw new InvalidOperationException($"Invalid opkind: '{parts[0]}'"); } }
public TimeSpan Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { var str = reader.ReadStringSegmentUnsafe(); var array = str.Array; var i = str.Offset; var len = str.Count; var to = str.Offset + len; // check day exists var hasDay = false; { var foundDot = false; var foundColon = false; for (var j = i; j < to; j++) { if (array[j] == '.') { if (foundColon) { break; } foundDot = true; } else if (array[j] == ':') { if (foundDot) { hasDay = true; } foundColon = true; } } } // check sign var minus = false; if (array[i] == '-') { minus = true; i++; } var day = 0; if (hasDay) { const int maxDayLength = 8 + 1; // {Day}. var dayCharacters = new byte[maxDayLength]; for (; array[i] != '.'; i++) { dayCharacters[day++] = array[i]; } day = new JsonReader(dayCharacters).ReadInt32(); i++; // skip '.' } var hour = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)':') { goto ERROR; } var minute = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)':') { goto ERROR; } var second = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); var ticks = 0; if (i < to && array[i] == '.') { i++; // *7. if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1000000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 100000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 10000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 100; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 10; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1; i++; // others, lack of precision while (i < to && NumberConverter.IsNumber(array[i])) { i++; } } END_TICKS: // be careful to overflow var ts = new TimeSpan(day, hour, minute, second); var tk = TimeSpan.FromTicks(ticks); return(minus ? ts.Negate().Subtract(tk) : ts.Add(tk)); ERROR: throw new InvalidOperationException("invalid TimeSpan format. value:" + StringEncoding.UTF8.GetString(str.Array, str.Offset, str.Count)); }
public void NegativeNumberNotSupportedTest_Error() { NumberConverter numberConverter = new NumberConverter(); var actual = numberConverter.ToWord(-5); }
public void SetUp() { numberConverter = new NumberConverter(); }
private void SetBinding() { bool is_null = false; if (_entity == null) { _entity = new EntitySupplier(); is_null = true; } // マスタコントロールPropertyChanged _entity.PropertyChanged += this.utlCustomer.MstID_Changed; _entity.PropertyChanged += this.utlZip.MstID_Changed; NumberConverter nmConvDecm0 = new NumberConverter(); #region Bind string _customerId = ExCast.zNumZeroNothingFormat(this.utlCustomer.txtID.Text.Trim()); string _customerNm = this.utlCustomer.txtNm.Text.Trim(); // バインド Binding BindingCustomerId = new Binding("_customer_id"); BindingCustomerId.Mode = BindingMode.TwoWay; BindingCustomerId.Source = _entity; this.utlCustomer.txtID.SetBinding(TextBox.TextProperty, BindingCustomerId); this.utlID.txtID2.SetBinding(TextBox.TextProperty, BindingCustomerId); Binding BindingCustomerName = new Binding("_customer_nm"); BindingCustomerName.Mode = BindingMode.TwoWay; BindingCustomerName.Source = _entity; this.utlCustomer.txtNm.SetBinding(TextBox.TextProperty, BindingCustomerName); if (is_null == false) { this.utlCustomer.txtID.Text = _customerId; this.utlCustomer.txtNm.Text = _customerNm; } Binding BindingName = new Binding("_name"); BindingName.Mode = BindingMode.TwoWay; BindingName.Source = _entity; this.txtName.SetBinding(TextBox.TextProperty, BindingName); Binding BindingKana = new Binding("_kana"); BindingKana.Mode = BindingMode.TwoWay; BindingKana.Source = _entity; this.txtKana.SetBinding(TextBox.TextProperty, BindingKana); Binding BindingAboutName = new Binding("_about_name"); BindingAboutName.Mode = BindingMode.TwoWay; BindingAboutName.Source = _entity; this.txtAdoutName.SetBinding(TextBox.TextProperty, BindingAboutName); Binding BindingZipCodeFrom = new Binding("_zip_code_from"); BindingZipCodeFrom.Mode = BindingMode.TwoWay; BindingZipCodeFrom.Source = _entity; this.utlZip.txtZipNo1.SetBinding(TextBox.TextProperty, BindingZipCodeFrom); Binding BindingZipCodeTo = new Binding("_zip_code_to"); BindingZipCodeTo.Mode = BindingMode.TwoWay; BindingZipCodeTo.Source = _entity; this.utlZip.txtZipNo2.SetBinding(TextBox.TextProperty, BindingZipCodeTo); this.utlZip.is_zip_from_first_flg = true; this.utlZip.is_zip_to_first_flg = true; Binding BindingAdress1 = new Binding("_adress1"); BindingAdress1.Mode = BindingMode.TwoWay; BindingAdress1.Source = _entity; this.utlZip.SetBinding(Utl_Zip.UserControlAdress1Property, BindingAdress1); Binding BindingAdress2 = new Binding("_adress2"); BindingAdress2.Mode = BindingMode.TwoWay; BindingAdress2.Source = _entity; this.utlZip.SetBinding(Utl_Zip.UserControlAdress2Property, BindingAdress2); Binding BindingStationName = new Binding("_station_name"); BindingStationName.Mode = BindingMode.TwoWay; BindingStationName.Source = _entity; this.txtStationName.SetBinding(TextBox.TextProperty, BindingStationName); Binding BindingPostName = new Binding("_post_name"); BindingPostName.Mode = BindingMode.TwoWay; BindingPostName.Source = _entity; this.txtPostName.SetBinding(TextBox.TextProperty, BindingPostName); Binding BindingPersonName = new Binding("_person_name"); BindingPersonName.Mode = BindingMode.TwoWay; BindingPersonName.Source = _entity; this.txtPersonName.SetBinding(TextBox.TextProperty, BindingPersonName); Binding BindingTitleId = new Binding("_title_id"); BindingTitleId.Mode = BindingMode.TwoWay; BindingTitleId.Source = _entity; this.utlTitle.txtID.SetBinding(TextBox.TextProperty, BindingTitleId); Binding BindingTitleName = new Binding("_title_name"); BindingTitleName.Mode = BindingMode.TwoWay; BindingTitleName.Source = _entity; this.utlTitle.txtNm.SetBinding(TextBox.TextProperty, BindingTitleName); Binding BindingTel = new Binding("_tel"); BindingTel.Mode = BindingMode.TwoWay; BindingTel.Source = _entity; this.txtTel.SetBinding(TextBox.TextProperty, BindingTel); Binding BindingFax = new Binding("_fax"); BindingFax.Mode = BindingMode.TwoWay; BindingFax.Source = _entity; this.txtFax.SetBinding(TextBox.TextProperty, BindingFax); Binding BindingMailAdress = new Binding("_mail_adress"); BindingMailAdress.Mode = BindingMode.TwoWay; BindingMailAdress.Source = _entity; this.txtMail.SetBinding(TextBox.TextProperty, BindingMailAdress); Binding BindigDiaplayDivisionId = new Binding("_display_division_id"); BindigDiaplayDivisionId.Mode = BindingMode.TwoWay; BindigDiaplayDivisionId.Source = _entity; this.utlDisplay.txtID.SetBinding(TextBox.TextProperty, BindigDiaplayDivisionId); Binding BindigDiaplayDivisionNm = new Binding("_display_division_nm"); BindigDiaplayDivisionNm.Mode = BindingMode.TwoWay; BindigDiaplayDivisionNm.Source = _entity; this.utlDisplay.txtNm.SetBinding(TextBox.TextProperty, BindigDiaplayDivisionNm); Binding BindigMemo = new Binding("_memo"); BindigMemo.Mode = BindingMode.TwoWay; BindigMemo.Source = _entity; this.txtMemo.SetBinding(TextBox.TextProperty, BindigMemo); #endregion if (ExCast.IsNumeric(this.utlID.txtID.Text.Trim())) { this.utlID.txtID.SetZeroToNullString(); } this.utlID.txtID.FormatToID(); this.utlTitle.txtID.SetZeroToNullString(); this.utlCustomer.txtID.SetZeroToNullString(); this.utlCustomer.txtID.FormatToID(); if (ExCast.zCInt(_entity._id) == 0) { _entity._divide_permission_id = 2; _entity._display_division_id = 1; } }
public DateTime Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { var str = reader.ReadStringSegmentUnsafe(); var array = str.Array; var i = str.Offset; var len = str.Count; var to = str.Offset + str.Count; // YYYY if (len == 4) { var y = (array[i++] - (byte)'0') * 1000 + (array[i++] - (byte)'0') * 100 + (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); return(new DateTime(y, 1, 1)); } // YYYY-MM if (len == 7) { var y = (array[i++] - (byte)'0') * 1000 + (array[i++] - (byte)'0') * 100 + (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'-') { goto ERROR; } var m = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); return(new DateTime(y, m, 1)); } // YYYY-MM-DD if (len == 10) { var y = (array[i++] - (byte)'0') * 1000 + (array[i++] - (byte)'0') * 100 + (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'-') { goto ERROR; } var m = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'-') { goto ERROR; } var d = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); return(new DateTime(y, m, d)); } // range-first section requires 19 if (len < 19) { goto ERROR; } var year = (array[i++] - (byte)'0') * 1000 + (array[i++] - (byte)'0') * 100 + (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'-') { goto ERROR; } var month = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'-') { goto ERROR; } var day = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)'T') { goto ERROR; } var hour = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)':') { goto ERROR; } var minute = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)':') { goto ERROR; } var second = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); int ticks = 0; if (i < to && array[i] == '.') { i++; // *7. if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1000000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 100000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 10000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 100; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 10; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1; i++; // others, lack of precision while (i < to && NumberConverter.IsNumber(array[i])) { i++; } } END_TICKS: var kind = DateTimeKind.Unspecified; if (i < to && array[i] == 'Z') { kind = DateTimeKind.Utc; } else if (i < to && (array[i] == '-' || array[i] == '+')) { if (!(i + 5 < to)) { goto ERROR; } kind = DateTimeKind.Local; var minus = array[i++] == '-'; var h = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); i++; var m = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); var offset = new TimeSpan(h, m, 0); if (minus) { offset = offset.Negate(); } return(new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc).AddTicks(ticks).Subtract(offset).ToLocalTime()); } return(new DateTime(year, month, day, hour, minute, second, kind).AddTicks(ticks)); ERROR: throw new InvalidOperationException("invalid datetime format. value:" + StringEncoding.UTF8.GetString(str.Array, str.Offset, str.Count)); }
public TimeSpan Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { var str = reader.ReadStringSegmentUnsafe(); var array = str.Array; var i = str.Offset; var len = str.Count; var to = str.Offset + str.Count; // check day exists bool hasDay = false; { bool foundDot = false; bool foundColon = false; for (int j = i; j < to; j++) { if (array[j] == '.') { if (foundColon) { break; } foundDot = true; } else if (array[j] == ':') { if (foundDot) { hasDay = true; } foundColon = true; } } } // check sign var minus = false; if (array[i] == '-') { minus = true; i++; } var day = 0; if (hasDay) { var poolArray = BufferPool.Default.Rent(); try { for (; array[i] != '.'; i++) { poolArray[day++] = array[i]; } poolArray[day] = array[i++]; // skip '.' and fix #105 day = new JsonReader(poolArray).ReadInt32(); } finally { BufferPool.Default.Return(poolArray); } } var hour = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)':') { goto ERROR; } var minute = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); if (array[i++] != (byte)':') { goto ERROR; } var second = (array[i++] - (byte)'0') * 10 + (array[i++] - (byte)'0'); int ticks = 0; if (i < to && array[i] == '.') { i++; // *7. if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1000000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 100000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 10000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1000; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 100; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 10; i++; if (!(i < to) || !NumberConverter.IsNumber(array[i])) { goto END_TICKS; } ticks += (array[i] - (byte)'0') * 1; i++; // others, lack of precision while (i < to && NumberConverter.IsNumber(array[i])) { i++; } } END_TICKS: // be careful to overflow var ts = new TimeSpan(day, hour, minute, second); var tk = TimeSpan.FromTicks(ticks); return((minus) ? ts.Negate().Subtract(tk) : ts.Add(tk)); ERROR: throw new InvalidOperationException("invalid timespan format. value:" + StringEncoding.UTF8.GetString(str.Array, str.Offset, str.Count)); }