Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

50 lines
1.4 KiB

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Infrastructure.MongoDb
{
public static class BsonHelper
{
private const string TypeBson = "§type";
private const string TypeJson = "$json";
public static string UnescapeBson(this string value)
{
if (value == TypeBson)
{
return TypeJson;
}
return ReplaceFirstCharacter(value, '§', '$');
}
public static string EscapeJson(this string value)
{
if (value == TypeJson)
{
return TypeBson;
}
return ReplaceFirstCharacter(value, '$', '§');
}
private static string ReplaceFirstCharacter(string value, char toReplace, char replacement)
{
if (value.Length == 0 || value[0] != toReplace)
{
return value;
}
if (value.Length == 1)
{
return toReplace.ToString();
}
return replacement + value.Substring(1);
}
}
}