Skip to content

Commit ffdaf7c

Browse files
committed
use framework string decoding for non-SL versions (thanks @tt)
1 parent cbfa798 commit ffdaf7c

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

RestSharp.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestSharp.WindowsPhone", "RestSharp.WindowsPhone\RestSharp.WindowsPhone.csproj", "{F4D48DF6-316E-4963-B5C1-59CA39B431B7}"
1313
EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{E709A928-A45C-4622-A35C-CCD8EE44CA80}"
15+
ProjectSection(SolutionItems) = preProject
16+
restsharp.nuspec = restsharp.nuspec
17+
EndProjectSection
1518
EndProject
1619
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestSharp.WindowsPhone.Mango", "RestSharp.WindowsPhone.Mango\RestSharp.WindowsPhone.Mango.csproj", "{71647E33-714F-4975-8368-71B075045272}"
1720
EndProject

RestSharp/Extensions/MiscExtensions.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,15 @@ public static string AsString(this JToken token, CultureInfo culture)
107107
/// <returns>The byte as a string.</returns>
108108
public static string AsString(this byte[] buffer)
109109
{
110-
if (buffer == null || buffer.Length == 0)
111-
return "";
112-
113110
// Ansi as default
114111
Encoding encoding = Encoding.UTF8;
115112

113+
#if FRAMEWORK
114+
return encoding.GetString(buffer);
115+
#else
116+
if (buffer == null || buffer.Length == 0)
117+
return "";
118+
116119
/*
117120
EF BB BF UTF-8
118121
FF FE UTF-16 little endian
@@ -133,16 +136,7 @@ FE FF UTF-16 big endian
133136
{
134137
encoding = Encoding.BigEndianUnicode; // utf-16be
135138
}
136-
#if FRAMEWORK
137-
else if (buffer[0] == 0 && buffer[1] == 0 && buffer[2] == 0xfe && buffer[3] == 0xff)
138-
{
139-
encoding = Encoding.UTF32;
140-
}
141-
else if (buffer[0] == 0x2b && buffer[1] == 0x2f && buffer[2] == 0x76)
142-
{
143-
encoding = Encoding.UTF7;
144-
}
145-
#endif
139+
146140
using (MemoryStream stream = new MemoryStream())
147141
{
148142
stream.Write(buffer, 0, buffer.Length);
@@ -152,7 +146,7 @@ FE FF UTF-16 big endian
152146
return reader.ReadToEnd();
153147
}
154148
}
149+
#endif
155150
}
156-
157151
}
158152
}

0 commit comments

Comments
 (0)