/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/EmbeddedLanguages/VirtualChars/RuneExtensions.cs
49 строк
2 KB
Cyrus Najmabadi
Rename to 'Value'
02 окт 2025, 02:54
02 окт 2025, 02:54
5ea7323
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Text; using Microsoft.CodeAnalysis.EmbeddedLanguages.VirtualChars; namespace Microsoft.CodeAnalysis.CSharp.EmbeddedLanguages.VirtualChars; internal static class Extensions { public static bool TryGetEscapeCharacter(this VirtualChar ch, out char escapedChar) => TryGetEscapeCharacter(ch.Value, out escapedChar); public static bool TryGetEscapeCharacter(this Rune rune, out char escapedChar) { escapedChar = '\0'; return rune.Utf16SequenceLength == 1 && TryGetEscapeCharacter((char)rune.Value, out escapedChar); } private static bool TryGetEscapeCharacter(char ch, out char escapedChar) { // Keep in sync with CSharpVirtualCharService.TryAddSingleCharacterEscape switch (ch) { // Note: we don't care about single quote as that doesn't need to be escaped when // producing a normal C# string literal. // case '\'': // escaped characters that translate to themselves. case '"': escapedChar = '"'; return true; case '\\': escapedChar = '\\'; return true; // translate escapes as per C# spec 2.4.4.4 case '\0': escapedChar = '0'; return true; case '\a': escapedChar = 'a'; return true; case '\b': escapedChar = 'b'; return true; case '\f': escapedChar = 'f'; return true; case '\n': escapedChar = 'n'; return true; case '\r': escapedChar = 'r'; return true; case '\t': escapedChar = 't'; return true; case '\v': escapedChar = 'v'; return true; } escapedChar = default; return false; } }