本文整理汇总了C#中MutableString.GetByteCount方法的典型用法代码示例。如果您正苦于以下问题:C# MutableString.GetByteCount方法的具体用法?C# MutableString.GetByteCount怎么用?C# MutableString.GetByteCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableString
的用法示例。
在下文中一共展示了MutableString.GetByteCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: AppendRawBytes
private void AppendRawBytes(MutableString/*!*/ buffer, int count) {
Debug.Assert(count > 0);
int remaining = count;
if (_bufferCount > 0) {
int c = Math.Min(_bufferCount, count);
buffer.Append(_buffer, _bufferStart, c);
ConsumeBuffered(c);
remaining -= c;
}
if (count == Int32.MaxValue) {
const int chunk = 1024;
int done = buffer.GetByteCount();
int bytesRead;
do {
buffer.Append(_stream, chunk);
bytesRead = buffer.GetByteCount() - done;
done += bytesRead;
} while (bytesRead == chunk);
} else {
buffer.Append(_stream, remaining);
}
}
示例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: GetSubstring
public static MutableString GetSubstring(ConversionStorage<int>/*!*/ fixnumCast, MutableString/*!*/ self, [NotNull]Range/*!*/ range) {
int begin, count;
if (!NormalizeSubstringRange(fixnumCast, range, self.GetByteCount(), out begin, out count)) {
return null;
}
return (count < 0) ? self.CreateInstance().TaintBy(self) : GetSubstring(self, begin, count);
}
示例5: GetChar
public static object GetChar(MutableString/*!*/ self, [DefaultProtocol]int index) {
return InExclusiveRangeNormalized(self.GetByteCount(), ref index) ? ScriptingRuntimeHelpers.Int32ToObject(self.GetByte(index)) : null;
}
示例6: LastIndexOf
public static object LastIndexOf(MutableString/*!*/ self,
int character, [DefaultProtocol, DefaultParameterValue(Int32.MaxValue)]int start) {
if (!self.IsBinaryEncoded && !self.Encoding.IsKCoding && !self.IsAscii()) {
throw RubyExceptions.CreateTypeError("type mismatch: Fixnum given");
}
int byteCount = self.GetByteCount();
start = IListOps.NormalizeIndex(byteCount, start);
if (start < 0 || character < 0 || character > 255) {
return null;
}
if (start >= byteCount) {
start = byteCount - 1;
}
int result = self.LastIndexOf((byte)character, start);
return (result != -1) ? ScriptingRuntimeHelpers.Int32ToObject(result) : null;
}
示例7: GetLength
public static int GetLength(MutableString/*!*/ self) {
return (self.Encoding.IsKCoding) ? self.GetByteCount() : self.GetCharCount();
}
示例8: AppendRawBytes
private void AppendRawBytes(MutableString/*!*/ buffer, int count) {
Debug.Assert(count > 0);
int remaining = count;
while (_bufferSize > 0) {
buffer.Append(ReadBufferByte());
remaining--;
}
if (count == Int32.MaxValue) {
const int chunk = 1024;
int done = buffer.GetByteCount();
int bytesRead;
do {
buffer.Append(_stream, chunk);
bytesRead = buffer.GetByteCount() - done;
done += bytesRead;
} while (bytesRead == chunk);
} else {
buffer.Append(_stream, remaining);
}
}
示例9: 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');
}
}
示例10: 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;
}
示例11: GetByteCount
public static int GetByteCount(MutableString/*!*/ self) {
return self.GetByteCount();
}
示例12: 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);
}
示例13: ReadLine
public MutableString ReadLine(MutableString/*!*/ separator, RubyEncoding/*!*/ encoding, bool preserveEndOfLines) {
int b = ReadByteNormalizeEoln(preserveEndOfLines);
if (b == -1) {
return null;
}
int separatorOffset = 0;
int separatorLength = separator.GetByteCount();
MutableString result = MutableString.CreateBinary(encoding);
do {
result.Append((byte)b);
if (b == separator.GetByte(separatorOffset)) {
if (separatorOffset == separatorLength - 1) {
break;
}
separatorOffset++;
} else if (separatorOffset > 0) {
separatorOffset = 0;
}
b = ReadByteNormalizeEoln(preserveEndOfLines);
} while (b != -1);
return result;
}
示例14: Join
public static MutableString/*!*/ Join(JoinConversionStorage/*!*/ conversions, IList/*!*/ self, MutableString separator) {
var parts = new List<MutableString>(self.Count);
bool? isBinary = (separator != null) ? separator.IsBinary : (bool?)null;
Dictionary<object, bool> seen = null;
// build a list of strings to join:
JoinRecursive(conversions, self, parts, ref isBinary, ref seen);
if (parts.Count == 0) {
return MutableString.CreateEmpty();
}
if (separator != null && separator.IsBinary != isBinary && !separator.IsAscii()) {
isBinary = true;
}
// calculate length:
MutableString any = separator;
int length = (separator != null) ? (isBinary.HasValue && isBinary.Value ? separator.GetByteCount() : separator.GetCharCount()) * (parts.Count - 1) : 0;
for (int i = 0, n = parts.Count; i < n; i++) {
var part = parts[i];
if (part != null) {
length += (isBinary.HasValue && isBinary.Value) ? part.GetByteCount() : part.GetCharCount();
if (any == null) {
any = part;
}
}
}
if (any == null) {
return MutableString.CreateEmpty();
}
var result = isBinary.HasValue && isBinary.Value ?
MutableString.CreateBinary(length, any.Encoding) :
MutableString.CreateMutable(length, any.Encoding);
for (int i = 0, n = parts.Count; i < n; i++) {
var part = parts[i];
if (separator != null && i > 0) {
result.Append(separator);
}
if (part != null) {
result.Append(part);
result.TaintBy(part);
}
}
if (separator != null) {
result.TaintBy(separator);
}
if (!result.IsTainted || !result.IsUntrusted) {
result.TaintBy(self, conversions.Context);
}
return result;
}
示例15: Unpack
/*!*/
public static RubyArray Unpack(MutableString/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ format)
{
RubyArray result = new RubyArray(1 + self.Length / 2);
// TODO: encodings
int position = 0;
int length = self.GetByteCount();
foreach (FormatDirective directive in FormatDirective.Enumerate(format.ToString())) {
int count, maxCount;
int nilCount = 0;
switch (directive.Directive) {
case '@':
if (directive.Count.HasValue) {
if (directive.Count.Value > length) {
throw RubyExceptions.CreateArgumentError("@ outside of string");
}
position = directive.Count.Value > 0 ? directive.Count.Value : 0;
} else {
position = length;
}
break;
case 'A':
case 'a':
case 'Z':
result.Add(ReadString(self, directive.Directive, directive.Count, ref position));
break;
case 'B':
case 'b':
result.Add(ReadBits(self, directive.Count, ref position, directive.Directive == 'b'));
break;
case 'c':
count = CalculateCounts(length - position, directive.Count, sizeof(sbyte), out nilCount);
for (int j = 0; j < count; j++) {
result.Add((int)unchecked((sbyte)self.GetByte(position++)));
}
break;
case 'C':
count = CalculateCounts(length - position, directive.Count, sizeof(byte), out nilCount);
for (int j = 0; j < count; j++) {
result.Add((int)self.GetByte(position++));
}
break;
case 'd': // 8-byte native-endian
case 'D':
count = CalculateCounts(length - position, directive.Count, sizeof(double), out nilCount);
for (int j = 0; j < count; j++) {
result.Add(ReadDouble(self, ref position, false));
}
break;
case 'e': // 4-byte little-endian
count = CalculateCounts(length - position, directive.Count, sizeof(float), out nilCount);
for (int j = 0; j < count; j++) {
result.Add((double)ReadSingle(self, ref position, !BitConverter.IsLittleEndian));
}
break;
case 'E': // 8-byte little-endian
count = CalculateCounts(length - position, directive.Count, sizeof(double), out nilCount);
for (int j = 0; j < count; j++) {
result.Add(ReadDouble(self, ref position, !BitConverter.IsLittleEndian));
}
break;
case 'f': // 4-byte native-endian
case 'F':
count = CalculateCounts(length - position, directive.Count, sizeof(float), out nilCount);
for (int j = 0; j < count; j++) {
result.Add((double)ReadSingle(self, ref position, false));
}
break;
case 'g': // 4-byte big-endian
count = CalculateCounts(length - position, directive.Count, sizeof(float), out nilCount);
for (int j = 0; j < count; j++) {
result.Add((double)ReadSingle(self, ref position, BitConverter.IsLittleEndian));
}
break;
case 'G': // 8-byte big-endian
count = CalculateCounts(length - position, directive.Count, sizeof(double), out nilCount);
for (int j = 0; j < count; j++) {
result.Add(ReadDouble(self, ref position, BitConverter.IsLittleEndian));
}
break;
case 'i':
case 'l': // signed 4-byte native-endian
count = CalculateCounts(length - position, directive.Count, sizeof(int), out nilCount);
for (int j = 0; j < count; j++) {
result.Add(unchecked((int)ReadUInt32(self, ref position, false)));
}
break;
//.........这里部分代码省略.........