@@ -63,13 +63,22 @@ public sealed class EmitterSettings
6363 /// </summary>
6464 public bool IndentSequences { get ; }
6565
66+ /// <summary>
67+ /// If true, then 4-byte UTF-32 characters are broken into two 2-byte code-points.
68+ /// </summary>
69+ /// <remarks>
70+ /// This ensures compatibility with JSON format, as it does not allow '\Uxxxxxxxxx'
71+ /// and instead expects two escaped 2-byte character '\uxxxx\uxxxx'.
72+ /// </remarks>
73+ public bool UseUtf16SurrogatePairs { get ; }
74+
6675 public static readonly EmitterSettings Default = new EmitterSettings ( ) ;
6776
6877 public EmitterSettings ( )
6978 {
7079 }
7180
72- public EmitterSettings ( int bestIndent , int bestWidth , bool isCanonical , int maxSimpleKeyLength , bool skipAnchorName = false , bool indentSequences = false , string ? newLine = null )
81+ public EmitterSettings ( int bestIndent , int bestWidth , bool isCanonical , int maxSimpleKeyLength , bool skipAnchorName = false , bool indentSequences = false , bool useUtf16SurrogatePairs = false , string ? newLine = null )
7382 {
7483 if ( bestIndent < 2 || bestIndent > 9 )
7584 {
@@ -92,6 +101,7 @@ public EmitterSettings(int bestIndent, int bestWidth, bool isCanonical, int maxS
92101 MaxSimpleKeyLength = maxSimpleKeyLength ;
93102 SkipAnchorName = skipAnchorName ;
94103 IndentSequences = indentSequences ;
104+ UseUtf16SurrogatePairs = useUtf16SurrogatePairs ;
95105 NewLine = newLine ?? Environment . NewLine ;
96106 }
97107
@@ -104,6 +114,7 @@ public EmitterSettings WithBestIndent(int bestIndent)
104114 MaxSimpleKeyLength ,
105115 SkipAnchorName ,
106116 IndentSequences ,
117+ UseUtf16SurrogatePairs ,
107118 NewLine
108119 ) ;
109120 }
@@ -117,6 +128,7 @@ public EmitterSettings WithBestWidth(int bestWidth)
117128 MaxSimpleKeyLength ,
118129 SkipAnchorName ,
119130 IndentSequences ,
131+ UseUtf16SurrogatePairs ,
120132 NewLine
121133 ) ;
122134 }
@@ -130,6 +142,7 @@ public EmitterSettings WithMaxSimpleKeyLength(int maxSimpleKeyLength)
130142 maxSimpleKeyLength ,
131143 SkipAnchorName ,
132144 IndentSequences ,
145+ UseUtf16SurrogatePairs ,
133146 NewLine
134147 ) ;
135148 }
@@ -143,6 +156,7 @@ public EmitterSettings WithNewLine(string newLine)
143156 MaxSimpleKeyLength ,
144157 SkipAnchorName ,
145158 IndentSequences ,
159+ UseUtf16SurrogatePairs ,
146160 newLine
147161 ) ;
148162 }
@@ -167,6 +181,7 @@ public EmitterSettings WithoutAnchorName()
167181 MaxSimpleKeyLength ,
168182 true ,
169183 IndentSequences ,
184+ UseUtf16SurrogatePairs ,
170185 NewLine
171186 ) ;
172187 }
@@ -180,6 +195,21 @@ public EmitterSettings WithIndentedSequences()
180195 MaxSimpleKeyLength ,
181196 SkipAnchorName ,
182197 true ,
198+ UseUtf16SurrogatePairs ,
199+ NewLine
200+ ) ;
201+ }
202+
203+ public EmitterSettings WithUtf16SurrogatePairs ( )
204+ {
205+ return new EmitterSettings (
206+ BestIndent ,
207+ BestWidth ,
208+ IsCanonical ,
209+ MaxSimpleKeyLength ,
210+ SkipAnchorName ,
211+ IndentSequences ,
212+ true ,
183213 NewLine
184214 ) ;
185215 }
0 commit comments