本文整理汇总了C#中Portable.Text.Encoding.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Portable.Text.Encoding.GetBytes方法的具体用法?C# Portable.Text.Encoding.GetBytes怎么用?C# Portable.Text.Encoding.GetBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Portable.Text.Encoding
的用法示例。
在下文中一共展示了Portable.Text.Encoding.GetBytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetText
/// <summary>
/// Sets the text content and the charset parameter in the Content-Type header.
/// </summary>
/// <remarks>
/// This method is similar to setting the <see cref="Text"/> property, but allows
/// specifying a charset encoding to use. Also updates the
/// <see cref="ContentType.Charset"/> property.
/// </remarks>
/// <param name="encoding">The charset encoding.</param>
/// <param name="text">The text content.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="encoding"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="text"/> is <c>null</c>.</para>
/// </exception>
public void SetText (Encoding encoding, string text)
{
if (encoding == null)
throw new ArgumentNullException ("encoding");
if (text == null)
throw new ArgumentNullException ("text");
ContentType.Parameters["charset"] = CharsetUtils.GetMimeCharset (encoding);
var content = new MemoryStream (encoding.GetBytes (text));
ContentObject = new ContentObject (content);
}
示例2: EncodeReferencesHeader
static byte[] EncodeReferencesHeader (ParserOptions options, FormatOptions format, Encoding charset, string field, string value)
{
var encoded = new StringBuilder ();
int lineLength = field.Length + 1;
int count = 0;
foreach (var reference in MimeUtils.EnumerateReferences (value)) {
if (count > 0 && lineLength + reference.Length + 3 > format.MaxLineLength) {
encoded.Append (format.NewLine);
encoded.Append ('\t');
lineLength = 1;
count = 0;
} else {
encoded.Append (' ');
lineLength++;
}
encoded.Append ('<').Append (reference).Append ('>');
lineLength += reference.Length + 2;
count++;
}
encoded.Append (format.NewLine);
return charset.GetBytes (encoded.ToString ());
}
示例3: EncodeReceivedHeader
static byte[] EncodeReceivedHeader (ParserOptions options, FormatOptions format, Encoding charset, string field, string value)
{
var tokens = new List<ReceivedTokenValue> ();
var rawValue = charset.GetBytes (value);
var encoded = new StringBuilder ();
int lineLength = field.Length + 1;
bool date = false;
int index = 0;
int count = 0;
while (index < rawValue.Length) {
ReceivedTokenValue token = null;
int startIndex = index;
if (!ParseUtils.SkipCommentsAndWhiteSpace (rawValue, ref index, rawValue.Length, false) || index >= rawValue.Length) {
tokens.Add (new ReceivedTokenValue (startIndex, index - startIndex));
break;
}
while (index < rawValue.Length && !rawValue[index].IsWhitespace ())
index++;
var atom = charset.GetString (rawValue, startIndex, index - startIndex);
for (int i = 0; i < ReceivedTokens.Length; i++) {
if (atom == ReceivedTokens[i].Atom) {
ReceivedTokens[i].Skip (rawValue, ref index);
if (ParseUtils.SkipCommentsAndWhiteSpace (rawValue, ref index, rawValue.Length, false)) {
if (index < rawValue.Length && rawValue[index] == (byte) ';') {
date = true;
index++;
}
}
token = new ReceivedTokenValue (startIndex, index - startIndex);
break;
}
}
if (token == null) {
if (ParseUtils.SkipCommentsAndWhiteSpace (rawValue, ref index, rawValue.Length, false)) {
while (index < rawValue.Length && !rawValue[index].IsWhitespace ())
index++;
}
token = new ReceivedTokenValue (startIndex, index - startIndex);
}
tokens.Add (token);
ParseUtils.SkipWhiteSpace (rawValue, ref index, rawValue.Length);
if (date && index < rawValue.Length) {
// slurp up the date (the final token)
tokens.Add (new ReceivedTokenValue (index, rawValue.Length - index));
break;
}
}
foreach (var token in tokens) {
var text = charset.GetString (rawValue, token.StartIndex, token.Length).TrimEnd ();
if (count > 0 && lineLength + text.Length + 1 > format.MaxLineLength) {
encoded.Append (format.NewLine);
encoded.Append ('\t');
lineLength = 1;
count = 0;
} else {
encoded.Append (' ');
lineLength++;
}
lineLength += text.Length;
encoded.Append (text);
count++;
}
encoded.Append (format.NewLine);
return charset.GetBytes (encoded.ToString ());
}
示例4: EncodeDkimSignatureHeader
static byte[] EncodeDkimSignatureHeader (ParserOptions options, FormatOptions format, Encoding charset, string field, string value)
{
var encoded = new StringBuilder ();
int lineLength = field.Length + 1;
var token = new StringBuilder ();
int index = 0;
while (index < value.Length) {
while (index < value.Length && IsWhiteSpace (value[index]))
index++;
int startIndex = index;
string name;
while (index < value.Length && value[index] != '=') {
if (!IsWhiteSpace (value[index]))
token.Append (value[index]);
index++;
}
name = value.Substring (startIndex, index - startIndex);
while (index < value.Length && value[index] != ';') {
if (!IsWhiteSpace (value[index]))
token.Append (value[index]);
index++;
}
if (index < value.Length && value[index] == ';') {
token.Append (';');
index++;
}
if (lineLength + token.Length + 1 > format.MaxLineLength || name == "bh" || name == "b") {
encoded.Append (format.NewLine);
encoded.Append ('\t');
lineLength = 1;
} else {
encoded.Append (' ');
lineLength++;
}
if (token.Length > format.MaxLineLength) {
switch (name) {
case "z":
EncodeDkimHeaderList (format, encoded, ref lineLength, token.ToString (), '|');
break;
case "h":
EncodeDkimHeaderList (format, encoded, ref lineLength, token.ToString (), ':');
break;
default:
EncodeDkimLongValue (format, encoded, ref lineLength, token.ToString ());
break;
}
} else {
encoded.Append (token.ToString ());
lineLength += token.Length;
}
token.Length = 0;
}
encoded.Append (format.NewLine);
return charset.GetBytes (encoded.ToString ());
}
示例5: EncodeMessageIdHeader
static byte[] EncodeMessageIdHeader (ParserOptions options, FormatOptions format, Encoding charset, string field, string value)
{
return charset.GetBytes (" " + value + format.NewLine);
}