本文整理汇总了C#中MutableString.GetByte方法的典型用法代码示例。如果您正苦于以下问题:C# MutableString.GetByte方法的具体用法?C# MutableString.GetByte怎么用?C# MutableString.GetByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableString
的用法示例。
在下文中一共展示了MutableString.GetByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadLine
private static MutableString ReadLine(MutableString/*!*/ content, MutableString separator, ref int position) {
int length = content.GetByteCount();
if (position >= length) {
return null;
}
int oldPosition = position;
if (separator == null) {
position = length;
} else if (separator.IsEmpty) {
// skip initial ends of line:
while (oldPosition < length && content.GetByte(oldPosition) == '\n') {
oldPosition++;
}
position = content.IndexOf(ParagraphSeparator, oldPosition);
position = (position != -1) ? position + 1 : length;
} else {
position = content.IndexOf(separator, oldPosition);
position = (position != -1) ? position + separator.Length : length;
}
return content.GetSlice(oldPosition, position - oldPosition);
}
示例2: ReadQuotedPrintable
/*!*/
private static MutableString ReadQuotedPrintable(MutableString/*!*/ data, ref int index)
{
MutableString result = MutableString.CreateBinary();
int length = data.GetByteCount();
int i = index;
while (i < length) {
byte c = data.GetByte(i++);
if (c == '=') {
if (i >= length) {
break;
}
c = data.GetByte(i);
if (c == '\n') {
i++;
continue;
}
if (c == '\r' && i + 1 < length && data.GetByte(i + 1) == '\n') {
i += 2;
continue;
}
int hi = Tokenizer.ToDigit(c);
if (hi >= 16) {
break;
}
i++;
if (i >= length) {
break;
}
int lo = Tokenizer.ToDigit(data.GetByte(i));
if (lo >= 16) {
break;
}
i++;
result.Append((byte)((hi << 4) | lo));
} else {
result.Append(c);
}
}
index = i;
return result;
}
示例3: GetChecksum
public static object GetChecksum(MutableString/*!*/ self, [DefaultProtocol, DefaultParameterValue(16)]int bitCount) {
int length = self.GetByteCount();
uint mask = (bitCount > 31) ? 0xffffffff : (1U << bitCount) - 1;
uint sum = 0;
for (int i = 0; i < length; i++) {
byte b = self.GetByte(i);
try {
checked { sum = (sum + b) & mask; }
} catch (OverflowException) {
return GetBigChecksum(self, i, sum, bitCount);
}
}
return (sum > Int32.MaxValue) ? (BigInteger)sum : (object)(int)sum;
}
示例4: GetChar
public static object GetChar(MutableString/*!*/ self, [DefaultProtocol]int index) {
return InExclusiveRangeNormalized(self, ref index) ? (object)(int)self.GetByte(index) : null;
}
示例5: RemoveCharInPlace
public static object RemoveCharInPlace(RubyContext/*!*/ context, MutableString/*!*/ self, [DefaultProtocol]int index) {
if (!InExclusiveRangeNormalized(self.GetByteCount(), ref index)) {
return null;
}
// TODO: optimize if the value is not read:
int result = self.GetByte(index);
self.Remove(index, 1);
return result;
}
示例6: EachByte
public static object EachByte(BlockParam block, MutableString/*!*/ self) {
if (block == null && self.Length > 0) {
throw RubyExceptions.NoBlockGiven();
}
int i = 0;
while (i < self.Length) {
object result;
if (block.Yield((int)self.GetByte(i), out result)) {
return result;
}
i++;
}
return self;
}
示例7: WriteBits
private static void WriteBits(Stream/*!*/ stream, int? countDef, bool reverse, MutableString/*!*/ str)
{
int length = str.GetByteCount();
int count = countDef ?? length;
int bits = Math.Min(count, length);
int paddingBits = (8 - bits % 8) % 8;
long resultLength = stream.Length +
(bits + paddingBits) / 8 +
((count - bits) + (count - bits) % 2) / 2;
// estimate the total length:
stream.SetLength(resultLength);
int b = 0;
int i = 0;
int s = reverse ? 0 : 7;
int ds = reverse ? +1 : -1;
while (i < bits) {
b |= (str.GetByte(i++) & 1) << s;
s += ds;
if (i % 8 == 0) {
stream.WriteByte((byte)b);
b = 0;
s = reverse ? 0 : 7;
}
}
if (paddingBits > 0) {
stream.WriteByte((byte)b);
}
stream.Position = resultLength;
}
示例8: ReadLine
public MutableString ReadLine(MutableString/*!*/ separator, RubyEncoding/*!*/ encoding, bool preserveEndOfLines) {
int b = ReadByteNormalizeEoln(preserveEndOfLines);
if (b == -1) {
return null;
}
int separatorOffset = 0;
MutableString result = MutableString.CreateBinary(encoding);
do {
result.Append((byte)b);
if (b == separator.GetByte(separatorOffset)) {
if (separatorOffset == separator.Length - 1) {
break;
}
separatorOffset++;
} else if (separatorOffset > 0) {
separatorOffset = 0;
}
b = ReadByteNormalizeEoln(preserveEndOfLines);
} while (b != -1);
return result;
}
示例9: ReadUtf8CodePoint
private static int ReadUtf8CodePoint(MutableString/*!*/ data, ref int index)
{
int length = data.GetByteCount();
if (index >= length) {
return -1;
}
int b = data.GetByte(index++);
int count, mask;
if ((b & 0x80) == 0) {
count = 1;
mask = 0xff;
} else if ((b & 0xe0) == 0xc0) {
count = 2;
mask = 0x1f;
} else if ((b & 0xf0) == 0xe0) {
count = 3;
mask = 0x0f;
} else if ((b & 0xf8) == 0xf0) {
count = 4;
mask = 0x07;
} else if ((b & 0xfc) == 0xf8) {
count = 5;
mask = 0x03;
} else if ((b & 0xfe) == 0xfc) {
count = 6;
mask = 0x01;
} else {
throw RubyExceptions.CreateArgumentError("malformed UTF-8 character");
}
int codepoint = b & mask;
for (int i = 1; i < count; i++) {
if (index >= length) {
throw RubyExceptions.CreateArgumentError(
"malformed UTF-8 character (expected {0} bytes, given {1} bytes)", count, i
);
}
b = data.GetByte(index++);
if ((b & 0xc0) != 0x80) {
throw RubyExceptions.CreateArgumentError("malformed UTF-8 character");
}
codepoint = (codepoint << 6) | (b & 0x3f);
}
int requiredCount;
int mark;
GetCodePointByteCount(codepoint, out requiredCount, out mark);
if (requiredCount != count) {
throw RubyExceptions.CreateArgumentError("redundant UTF-8 sequence");
}
return codepoint;
}
示例10: ToHex
/*!*/
private static MutableString ToHex(MutableString/*!*/ data, ref int index, int nibbleCount, bool swap)
{
int wholeChars = nibbleCount / 2;
MutableString hex = MutableString.CreateMutable(nibbleCount, RubyEncoding.Binary);
for (int i = 0; i < wholeChars; i++) {
byte b = data.GetByte(index++);
char loNibble = (b & 0x0F).ToLowerHexDigit();
char hiNibble = ((b & 0xF0) >> 4).ToLowerHexDigit();
if (swap) {
hex.Append(loNibble);
hex.Append(hiNibble);
} else {
hex.Append(hiNibble);
hex.Append(loNibble);
}
}
// the last nibble:
if ((nibbleCount & 1) != 0) {
int b = data.GetByte(index++);
if (swap) {
hex.Append((b & 0x0F).ToLowerHexDigit());
} else {
hex.Append(((b & 0xF0) >> 4).ToLowerHexDigit());
}
}
return hex;
}
示例11: ReadUInt64
// TODO: move to MutableString?
private static ulong ReadUInt64(MutableString/*!*/ data, ref int index, bool swap)
{
int i = index;
index += 8;
if (swap) {
return
((ulong)data.GetByte(i + 0) << 56) |
((ulong)data.GetByte(i + 1) << 48) |
((ulong)data.GetByte(i + 2) << 40) |
((ulong)data.GetByte(i + 3) << 32) |
((ulong)data.GetByte(i + 4) << 24) |
((ulong)data.GetByte(i + 5) << 16) |
((ulong)data.GetByte(i + 6) << 8) |
((ulong)data.GetByte(i + 7));
} else {
return
((ulong)data.GetByte(i + 7) << 56) |
((ulong)data.GetByte(i + 6) << 48) |
((ulong)data.GetByte(i + 5) << 40) |
((ulong)data.GetByte(i + 4) << 32) |
((ulong)data.GetByte(i + 3) << 24) |
((ulong)data.GetByte(i + 2) << 16) |
((ulong)data.GetByte(i + 1) << 8) |
((ulong)data.GetByte(i + 0));
}
}
示例12: ReadUInt32
private static uint ReadUInt32(MutableString/*!*/ data, ref int index, bool swap)
{
int i = index;
index += 4;
if (swap) {
return
((uint)data.GetByte(i + 0) << 24) |
((uint)data.GetByte(i + 1) << 16) |
((uint)data.GetByte(i + 2) << 8) |
((uint)data.GetByte(i + 3));
} else {
return
((uint)data.GetByte(i + 3) << 24) |
((uint)data.GetByte(i + 2) << 16) |
((uint)data.GetByte(i + 1) << 8) |
((uint)data.GetByte(i + 0));
}
}
示例13: ReadUInt16
private static ushort ReadUInt16(MutableString/*!*/ data, ref int index, bool swap)
{
int i = index;
index += 2;
if (swap) {
return (ushort)((data.GetByte(i + 0) << 8) | data.GetByte(i + 1));
} else {
return (ushort)((data.GetByte(i + 1) << 8) | data.GetByte(i + 0));
}
}
示例14: ReadString
/*!*/
private static MutableString ReadString(MutableString/*!*/ data, int trimMode, int? count, ref int offset)
{
int start = offset;
int e = data.GetByteCount();
if (count.HasValue) {
int end = start + count.Value;
if (end < e) {
e = end;
}
}
offset = e;
byte b;
switch (trimMode) {
case 'A':
while (--e >= start && ((b = data.GetByte(e)) == 0 || b == ' ')) { }
e++;
break;
case 'Z':
int i = start;
while (i < e && data.GetByte(i) != 0) { i++; }
if (!count.HasValue) {
offset = i + 1;
}
e = i;
break;
}
return data.GetSlice(start, e - start);
}
示例15: WritePrintedQuotable
/// <summary>
/// Printable characters: [33, 60], [62, 126], space (32), tab (9) but not at the end of line
/// Escaped: others =XX
/// Soft eolns (could be inserted anywhere, Ruby: after each count + 1 characters): =\n
/// </summary>
private static void WritePrintedQuotable(Stream/*!*/ stream, MutableString/*!*/ str, int bytesPerLine)
{
bytesPerLine++;
int lineLength = 0;
int length = str.GetByteCount();
for (int i = 0; i < length; i++) {
byte c = str.GetByte(i);
if (c >= 33 && c <= 60 || c >= 62 && c <= 126 || c == 9 || c == 32) {
stream.WriteByte(c);
lineLength++;
} else if (c == (byte)'\n') {
stream.WriteByte(c);
lineLength = 0;
} else {
stream.WriteByte((byte)'=');
stream.WriteByte((byte)(c >> 4).ToUpperHexDigit());
stream.WriteByte((byte)(c & 0x0f).ToUpperHexDigit());
lineLength += 3;
}
if (lineLength >= bytesPerLine) {
stream.WriteByte((byte)'=');
stream.WriteByte((byte)'\n');
lineLength = 0;
}
}
if (lineLength > 0) {
stream.WriteByte((byte)'=');
stream.WriteByte((byte)'\n');
}
}