Skip to content

Commit

Permalink
StringExtensions.Unquote methods
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvk committed Apr 19, 2016
1 parent 6ab967e commit 48b4e79
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Main/src/CodeJam.Main.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<Compile Include="Collections\EnumerableExtensions.Slice.cs" />
<Compile Include="Collections\QueryableExtensions.ApplyOrder.cs" />
<Compile Include="Collections\QueryableExtensions.cs" />
<Compile Include="Option.cs" />
<Compile Include="Structures\Option.cs" />
<Compile Include="Reflection\InfoOf`1.cs" />
<Compile Include="Reflection\ParamInfo.cs" />
<Compile Include="Services\IServicePublisher.cs" />
Expand Down Expand Up @@ -165,7 +165,7 @@
<Compile Include="Structures\ObjectPools\SharedPoolExtensions.cs" />
<Compile Include="Structures\ObjectPools\PooledObject.cs" />
<Compile Include="Structures\ObjectPools\ObjectPool.cs" />
<Compile Include="Option`1.cs" />
<Compile Include="Structures\Option`1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reflection\EnumHelper.cs" />
<Compile Include="Reflection\ExpressionHelper.cs" />
Expand Down
28 changes: 28 additions & 0 deletions Main/src/Strings/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,5 +268,33 @@ public static unsafe string ToHexString([NotNull] this byte[] data, [CanBeNull]

return result;
}

/// <summary>
/// Remove one set of leading and trailing double quote characters, if both are present.
/// </summary>
public static string Unquote(this string arg)
{
bool quoted;
return Unquote(arg, out quoted);
}

/// <summary>
/// Remove one set of leading and trailing double quote characters, if both are present.
/// </summary>
public static string Unquote(this string arg, out bool quoted) => Unquote(arg, '"', out quoted);

/// <summary>
/// Remove one set of leading and trailing d<paramref name="quotationChar"/>, if both are present.
/// </summary>
public static string Unquote(this string arg, char quotationChar, out bool quoted)
{
if (arg.Length > 1 && arg[0] == quotationChar && arg[arg.Length - 1] == quotationChar)
{
quoted = true;
return arg.Substring(1, arg.Length - 2);
}
quoted = false;
return arg;
}
}
}
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions NuGet/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CodeJam 1.0.0-beta10 Release Notes
What's new in 1.0.0-beta10
------------------------
* InterlockedOperations.Initialize and Update methods
* StringExtensions.Unquote methods
* Add defaultValue parameter to all Min/MaxByOrDefault overloads
* Additional overloads for Algorithms.EqualRange/UpperBound/LowerBound
* Memoize extended up to 8 arguments
Expand Down

0 comments on commit 48b4e79

Please sign in to comment.