@@ -139,17 +139,38 @@ public static SqlExpression StringTrim(SqlExpression _this)
139
139
return SqlDml . Trim ( _this ) ;
140
140
}
141
141
142
+ [ Compiler ( typeof ( string ) , nameof ( string . TrimStart ) ) ]
143
+ public static SqlExpression StringTrimStart ( SqlExpression _this )
144
+ {
145
+ return SqlDml . Trim ( _this , SqlTrimType . Leading ) ;
146
+ }
147
+
148
+ [ Compiler ( typeof ( string ) , nameof ( string . TrimEnd ) ) ]
149
+ public static SqlExpression StringTrimEnd ( SqlExpression _this )
150
+ {
151
+ return SqlDml . Trim ( _this , SqlTrimType . Trailing ) ;
152
+ }
153
+
142
154
private static SqlExpression GenericTrim ( SqlExpression _this , SqlExpression trimChars , SqlTrimType trimType )
143
155
{
144
- if ( trimChars is SqlNull )
156
+ if ( trimChars is SqlNull ) {
145
157
return SqlDml . Trim ( _this , trimType ) ;
146
- if ( ! ( trimChars is SqlContainer container ) )
147
- throw new NotSupportedException ( Strings . ExStringTrimSupportedOnlyWithConstants ) ;
148
- if ( ! ( container . Value is char [ ] chars ) )
149
- throw new NotSupportedException ( Strings . ExStringTrimSupportedOnlyWithConstants ) ;
150
- return chars . Length == 0
151
- ? SqlDml . Trim ( _this , trimType )
152
- : SqlDml . Trim ( _this , trimType , new string ( chars ) ) ;
158
+ }
159
+ if ( trimChars is SqlLiteral < char > oneChar ) {
160
+ return SqlDml . Trim ( _this , trimType , oneChar . Value . ToString ( ) ) ;
161
+ }
162
+ if ( trimChars is SqlContainer container && container . Value is char [ ] chars ) {
163
+ if ( chars . Length == 0 ) {
164
+ return SqlDml . Trim ( _this , trimType ) ;
165
+ }
166
+
167
+ var context = ExpressionTranslationContext . Current ;
168
+ var provider = context . ProviderInfo . ProviderName ;
169
+ return provider . Equals ( WellKnown . Provider . Firebird , StringComparison . Ordinal )
170
+ ? chars . Aggregate ( _this , ( current , @char ) => SqlDml . Trim ( current , trimType , @char . ToString ( ) ) )
171
+ : SqlDml . Trim ( _this , trimType , new string ( chars ) ) ;
172
+ }
173
+ throw new NotSupportedException ( Strings . ExStringTrimSupportedOnlyWithConstants ) ;
153
174
}
154
175
155
176
[ Compiler ( typeof ( string ) , nameof ( string . Trim ) ) ]
@@ -159,20 +180,41 @@ public static SqlExpression StringTrim(SqlExpression _this,
159
180
return GenericTrim ( _this , trimChars , SqlTrimType . Both ) ;
160
181
}
161
182
183
+ [ Compiler ( typeof ( string ) , nameof ( string . Trim ) ) ]
184
+ public static SqlExpression StringTrimOneChar ( SqlExpression _this ,
185
+ [ Type ( typeof ( char ) ) ] SqlExpression trimChar )
186
+ {
187
+ return GenericTrim ( _this , trimChar , SqlTrimType . Both ) ;
188
+ }
189
+
162
190
[ Compiler ( typeof ( string ) , nameof ( string . TrimStart ) ) ]
163
191
public static SqlExpression StringTrimStart ( SqlExpression _this ,
164
192
[ Type ( typeof ( char [ ] ) ) ] SqlExpression trimChars )
165
193
{
166
194
return GenericTrim ( _this , trimChars , SqlTrimType . Leading ) ;
167
195
}
168
196
197
+ [ Compiler ( typeof ( string ) , nameof ( string . TrimStart ) ) ]
198
+ public static SqlExpression StringTrimStartOneChar ( SqlExpression _this ,
199
+ [ Type ( typeof ( char ) ) ] SqlExpression trimChar )
200
+ {
201
+ return GenericTrim ( _this , trimChar , SqlTrimType . Leading ) ;
202
+ }
203
+
169
204
[ Compiler ( typeof ( string ) , nameof ( string . TrimEnd ) ) ]
170
205
public static SqlExpression StringTrimEnd ( SqlExpression _this ,
171
206
[ Type ( typeof ( char [ ] ) ) ] SqlExpression trimChars )
172
207
{
173
208
return GenericTrim ( _this , trimChars , SqlTrimType . Trailing ) ;
174
209
}
175
210
211
+ [ Compiler ( typeof ( string ) , nameof ( string . TrimEnd ) ) ]
212
+ public static SqlExpression StringTrimEndOneChar ( SqlExpression _this ,
213
+ [ Type ( typeof ( char ) ) ] SqlExpression trimChar )
214
+ {
215
+ return GenericTrim ( _this , trimChar , SqlTrimType . Trailing ) ;
216
+ }
217
+
176
218
[ Compiler ( typeof ( string ) , nameof ( string . Length ) , TargetKind . PropertyGet ) ]
177
219
public static SqlExpression StringLength ( SqlExpression _this )
178
220
{
0 commit comments