ReadUnicodeString() private method

private ReadUnicodeString ( int offset ) : string
offset int
return string
示例#1
0
            object INativeType.GetValue(MemoryHolder owner, object readingFrom, int offset, bool raw)
            {
                if (IsStringType)
                {
                    SimpleType st = (SimpleType)_type;
                    string     str;
                    if (st._type == SimpleTypeKind.Char)
                    {
                        str = owner.ReadAnsiString(offset, _length);
                    }
                    else
                    {
                        str = owner.ReadUnicodeString(offset, _length);
                    }

                    // remove any trailing nulls
                    for (int i = 0; i < str.Length; i++)
                    {
                        if (str[i] == '\x00')
                        {
                            return(str.Substring(0, i));
                        }
                    }

                    return(str);
                }

                _Array arr = (_Array)CreateInstance(Context.SharedContext);

                arr._memHolder = new MemoryHolder(owner.UnsafeAddress.Add(offset), ((INativeType)this).Size, owner);
                return(arr);
            }
示例#2
0
            internal object GetRawValue(MemoryHolder owner, int offset)
            {
                Debug.Assert(IsStringType);
                SimpleType st = (SimpleType)_type;

                if (st._type == SimpleTypeKind.Char)
                {
                    return(owner.ReadBytes(offset, _length));
                }
                else
                {
                    return(owner.ReadUnicodeString(offset, _length));
                }
            }
示例#3
0
            internal string GetRawValue(MemoryHolder owner, int offset)
            {
                Debug.Assert(IsStringType);
                SimpleType st = (SimpleType)_type;
                string     str;

                if (st._type == SimpleTypeKind.Char)
                {
                    str = owner.ReadAnsiString(offset, _length);
                }
                else
                {
                    str = owner.ReadUnicodeString(offset, _length);
                }

                return(str);
            }
示例#4
0
            object INativeType.GetValue(MemoryHolder owner, object readingFrom, int offset, bool raw)
            {
                if (_type is SimpleType st)
                {
                    if (st._type == SimpleTypeKind.Char)
                    {
                        var str = owner.ReadBytes(offset, _length);

                        // remove any trailing nulls
                        for (int i = 0; i < str.Count; i++)
                        {
                            if (str[i] == 0)
                            {
                                return(new Bytes(str.Substring(0, i)));
                            }
                        }

                        return(str);
                    }
                    if (st._type == SimpleTypeKind.WChar)
                    {
                        string str = owner.ReadUnicodeString(offset, _length);

                        // remove any trailing nulls
                        for (int i = 0; i < str.Length; i++)
                        {
                            if (str[i] == '\x00')
                            {
                                return(str.Substring(0, i));
                            }
                        }

                        return(str);
                    }
                }

                _Array arr = (_Array)CreateInstance(Context.SharedContext);

                arr.MemHolder = new MemoryHolder(owner.UnsafeAddress.Add(offset), ((INativeType)this).Size, owner);
                return(arr);
            }
示例#5
0
            internal string GetRawValue(MemoryHolder owner, int offset) {
                Debug.Assert(IsStringType);
                SimpleType st = (SimpleType)_type;
                string str;
                if (st._type == SimpleTypeKind.Char) {
                    str = owner.ReadAnsiString(offset, _length);
                } else {
                    str = owner.ReadUnicodeString(offset, _length);
                }

                return str;
            }
示例#6
0
            object INativeType.GetValue(MemoryHolder owner, object readingFrom, int offset, bool raw) {
                if (IsStringType) {
                    SimpleType st = (SimpleType)_type;
                    string str;
                    if (st._type == SimpleTypeKind.Char) {
                        str = owner.ReadAnsiString(offset, _length);
                    } else {
                        str = owner.ReadUnicodeString(offset, _length);
                    }

                    // remove any trailing nulls
                    for (int i = 0; i < str.Length; i++) {
                        if (str[i] == '\x00') {
                            return str.Substring(0, i);
                        }
                    }

                    return str;
                }

                _Array arr = (_Array)CreateInstance(Context.SharedContext);
                arr._memHolder = new MemoryHolder(owner.UnsafeAddress.Add(offset), ((INativeType)this).Size, owner);
                return arr;
            }
示例#7
0
            object INativeType.GetValue(MemoryHolder/*!*/ owner, int offset, bool raw) {
                object res;
                switch (_type) {
                    case SimpleTypeKind.Boolean: res = owner.ReadByte(offset) != 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False; break;
                    case SimpleTypeKind.Char: res = new string((char)owner.ReadByte(offset), 1); break;
                    case SimpleTypeKind.SignedByte: res = GetIntReturn((int)(sbyte)owner.ReadByte(offset)); break;
                    case SimpleTypeKind.UnsignedByte: res = GetIntReturn((int)owner.ReadByte(offset)); break;
                    case SimpleTypeKind.SignedShort: res = GetIntReturn((int)owner.ReadInt16(offset)); break;
                    case SimpleTypeKind.WChar: res = new string((char)owner.ReadInt16(offset), 1); break;
                    case SimpleTypeKind.UnsignedShort: res = GetIntReturn((int)(ushort)owner.ReadInt16(offset)); break;
                    case SimpleTypeKind.SignedInt: res = GetIntReturn((int)owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.UnsignedInt: res = GetIntReturn((uint)owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.UnsignedLong: res = GetIntReturn((uint)owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.SignedLong: res = GetIntReturn(owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.Single: res = GetSingleReturn(owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.Double: res = GetDoubleReturn(owner.ReadInt64(offset)); break;
                    case SimpleTypeKind.UnsignedLongLong: res = GetIntReturn((ulong)owner.ReadInt64(offset)); break;
                    case SimpleTypeKind.SignedLongLong: res = GetIntReturn(owner.ReadInt64(offset)); break;
                    case SimpleTypeKind.Object: res = GetObjectReturn(owner.ReadIntPtr(offset)); break;
                    case SimpleTypeKind.Pointer: res = ToPython(owner.ReadIntPtr(offset)); break;
                    case SimpleTypeKind.CharPointer: res = owner.ReadAnsiString(offset); break;
                    case SimpleTypeKind.WCharPointer: res = owner.ReadUnicodeString(offset); break;
                    default:
                        throw new InvalidOperationException();
                }

                if (!raw && IsSubClass) {
                    res = PythonCalls.Call(this, res);
                }

                return res;
            }
示例#8
0
            object INativeType.GetValue(MemoryHolder owner, int offset, bool raw) {
                if (IsStringType) {
                    SimpleType st = (SimpleType)_type;
                    string str;
                    if (st._type == SimpleTypeKind.Char) {
                        str = owner.ReadAnsiString(offset, _length);
                    } else {
                        str = owner.ReadUnicodeString(offset, _length);
                    }

                    // remove any trailing nulls
                    for (int i = 0; i < str.Length; i++) {
                        if (str[i] == '\x00') {
                            return str.Substring(0, i);
                        }
                    }

                    return str;
                }

                object[] res = new object[_length];
                for (int i = 0; i < res.Length; i++) {
                    res[i] = _type.GetValue(owner, checked(offset + _type.Size * i), raw);
                }

                return List.FromArrayNoCopy(res);
            }