@@ -22,8 +22,9 @@ namespace OneScript.StandardLibrary
2222 [ GlobalContext ( Category = "Операции со строками" ) ]
2323 public class StringOperations : GlobalContextBase < StringOperations >
2424 {
25- private static readonly System . Text . RegularExpressions . Regex _templateRe
26- = new System . Text . RegularExpressions . Regex ( @"(%%)|%(\d+)|%\((\d+)\)|%" ) ;
25+ private static readonly System . Text . RegularExpressions . Regex _templateRe
26+ = new System . Text . RegularExpressions . Regex ( @"(%%)|%(\d+)|%\((\d+)\)|%" ,
27+ System . Text . RegularExpressions . RegexOptions . Compiled ) ;
2728
2829 /// <summary>
2930 /// Получает строку на языке, заданном во втором параметре (коды языков в соответствии с ISO 639-1)
@@ -50,13 +51,13 @@ public bool StrStartsWith(string inputString, string searchString)
5051 {
5152 bool result = false ;
5253
53- if ( ! string . IsNullOrEmpty ( inputString ) )
54+ if ( ! string . IsNullOrEmpty ( inputString ) )
5455 {
5556 if ( ! string . IsNullOrEmpty ( searchString ) )
5657 {
5758 result = inputString . StartsWith ( searchString ) ;
5859 }
59- else throw StringOpException . StrStartsWith ( ) ;
60+ else throw StringOpException . StrStartsWith ( ) ;
6061 }
6162
6263 return result ;
@@ -73,7 +74,7 @@ public bool StrEndsWith(string inputString, string searchString)
7374 {
7475 bool result = false ;
7576
76- if ( ! string . IsNullOrEmpty ( inputString ) )
77+ if ( ! string . IsNullOrEmpty ( inputString ) )
7778 {
7879 if ( ! string . IsNullOrEmpty ( searchString ) )
7980 {
@@ -97,9 +98,9 @@ public ArrayImpl StrSplit(string inputString, string stringDelimiter, bool? incl
9798 {
9899 string [ ] arrParsed ;
99100 if ( includeEmpty == null )
100- includeEmpty = true ;
101-
102- if ( ! string . IsNullOrEmpty ( inputString ) )
101+ includeEmpty = true ;
102+
103+ if ( ! string . IsNullOrEmpty ( inputString ) )
103104 {
104105 arrParsed = inputString . Split ( stringDelimiter ? . ToCharArray ( ) ,
105106 ( bool ) includeEmpty ? StringSplitOptions . None : StringSplitOptions . RemoveEmptyEntries ) ;
@@ -120,8 +121,8 @@ public ArrayImpl StrSplit(string inputString, string stringDelimiter, bool? incl
120121 [ ContextMethod ( "СтрСоединить" , "StrConcat" ) ]
121122 public string StrConcat ( IBslProcess process , ArrayImpl input , string delimiter = null )
122123 {
123- var strings = input . Select ( x => x . AsString ( process ) ) ;
124-
124+ var strings = input . Select ( x => x . AsString ( process ) ) ;
125+
125126 return String . Join ( delimiter , strings ) ;
126127 }
127128
@@ -149,10 +150,10 @@ public int StrCompare(string first, string second)
149150 [ ContextMethod ( "СтрНайти" , "StrFind" ) ]
150151 public int StrFind ( string haystack , string needle , SearchDirection direction = SearchDirection . FromBegin , int startPos = 0 , int occurance = 1 )
151152 {
152- if ( needle . Length == 0 )
153+ if ( needle == null || needle . Length == 0 )
153154 return 1 ;
154155
155- int len = haystack . Length ;
156+ int len = haystack ? . Length ?? 0 ;
156157 if ( len == 0 )
157158 return 0 ;
158159
@@ -285,14 +286,14 @@ public StringOpException(BilingualString message) : base(message)
285286 public static StringOpException StrStartsWith ( )
286287 {
287288 return new StringOpException ( new BilingualString (
288- "Error calling context method (StrStartsWith ): Invalid parameter number '2' value " ,
289- "Ошибка при вызове метода контекста (СтрНачинаетсяС ): Недопустимое значение параметра номер '2'" ) ) ;
289+ "Ошибка при вызове метода контекста (СтрНачинаетсяС ): Недопустимое значение параметра номер '2'" ,
290+ "Error calling context method (StrStartsWith ): Invalid parameter number '2' value " ) ) ;
290291 }
291292 public static StringOpException StrEndsWith ( )
292293 {
293294 return new StringOpException ( new BilingualString (
294- "Error calling context method (StrEndsWith ): Invalid parameter number '2' value " ,
295- "Ошибка при вызове метода контекста (СтрЗаканчиваетсяНа ): Недопустимое значение параметра номер '2'" ) ) ;
295+ "Ошибка при вызове метода контекста (СтрЗаканчиваетсяНа ): Недопустимое значение параметра номер '2'" ,
296+ "Error calling context method (StrEndsWith ): Invalid parameter number '2' value " ) ) ;
296297 }
297298
298299 public static StringOpException TemplateSyntax ( int pos )
0 commit comments