mingyang_text 2023.6.3 → 2023.8.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +27 -0
  2. package/package.json +2 -4
  3. package/text.js +37 -12
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # introduction
2
+
3
+ * 一个字符串操作的函数集合
4
+ * a collection of string related functions
5
+ ---
6
+
7
+ <br>
8
+
9
+ # history
10
+
11
+ * 2023-08-26
12
+ > * 优化了字符串配对函数的参数顺序并增加了默认值
13
+ > * optimized the parameter order of string pairing function and added default values
14
+
15
+ > * 增加了个readme文件
16
+ > * added a readme file
17
+ ---
18
+
19
+ <br>
20
+
21
+ # author
22
+
23
+ * fujun wang(wang.fu.jun@qq.com)
24
+ * Wangjing Beijing China
25
+ * origin of the name : mingyang is my son's name
26
+ * last modified : 2023-08-26
27
+ ---
package/package.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
2
  "name": "mingyang_text",
3
- "version": "2023.06.03",
4
- "description": "MingYang Packet",
3
+ "version": "2023.08.26",
4
+ "description": "a collection of string related functions",
5
5
  "main": "text.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
9
9
  "keywords": [
10
- "mingyang",
11
- "mingyang/text",
12
10
  "text/bin_with",
13
11
  "text/end_with",
14
12
  "string/format",
package/text.js CHANGED
@@ -1,3 +1,15 @@
1
+ /**
2
+ author:王甫君
3
+ create time:2018-03-24
4
+ wang.fu.jun@qq.com
5
+ wx/qq:96211
6
+ ***************************************
7
+ */
8
+
9
+
10
+
11
+
12
+
1
13
 
2
14
  /**
3
15
  * 对【数字】或【字符】进行【左侧补齐】操作
@@ -491,7 +503,7 @@ module.exports.do_Byte_Truncate = func_Byte_Truncate;
491
503
 
492
504
 
493
505
  /**
494
- * 找到配对的坐标,匹配不上的时候返回-1
506
+ * 找到配对的坐标,匹配不上的时候返回-1
495
507
  * @param {"目标文本,例如【json串】"} args_Text
496
508
  * @param {"右侧的限度位置"} args_LimitIndex
497
509
  * @param {"当前字符的位置"} args_CurrentIndex
@@ -531,22 +543,22 @@ module.exports.do_EscapeChar = func_EscapeChar;
531
543
 
532
544
 
533
545
  /**
534
- * 找到配对的坐标,匹配不上的时候返回-1
546
+ * 返回一个数组,下标0:配对的坐标;下标1:缺失的结束文本个数;匹配不到的时候下标0为【-1】
535
547
  * @param {"目标文本,例如【json串】"} args_Text
536
- * @param {"转义字符,例如【\\】"} args_EscapeChar
537
548
  * @param {"开始文本,例如【(<】"} args_BinChar
538
549
  * @param {"结束文本,例如【)>】"} args_EndChar
539
550
  * @param {"开始位置,应是开始文本的下一位"} args_StartIndex
540
- * @param {"查找范围,通常是目标文本的长度"} args_Length
551
+ * @param {"查找范围,通常是目标文本的长度"} args_MaxLength
552
+ * @param {"转义字符,例如【\\】"} args_EscapeChar
541
553
  */
542
554
  function func_PairText
543
555
  (
544
556
  /*要处理的目标字符串*/ args_Text
545
- , /*转义字符例如【\\】*/ args_EscapeChar
546
557
  , /*开始字符例如【{[】*/ args_BinChar
547
558
  , /*结束字符例如【}]】*/ args_EndChar
548
- , /*应该是起始字符的位置+1*/ args_StartIndex
549
- , /*一般是输入字符的length*/ args_Length
559
+ , /*应该是起始字符的位置+1*/ args_StartIndex = 0
560
+ , /*一般是输入字符的length*/ args_MaxLength = 0
561
+ , /*转义字符例如【\\】*/ args_EscapeChar = null
550
562
  ) {
551
563
 
552
564
  //起步就是1个
@@ -564,8 +576,18 @@ function func_PairText
564
576
  }
565
577
 
566
578
 
567
-
568
-
579
+ {//参数校验
580
+ if (args_MaxLength == 0) {
581
+ args_MaxLength = args_Text.length;
582
+ }
583
+ if (args_StartIndex == 0) {
584
+ args_StartIndex = args_Text.indexOf(args_BinChar);
585
+ if (args_StartIndex == -1) {
586
+ return [args_Text.indexOf(args_EndChar, 0), args_Missing];
587
+ }
588
+ args_StartIndex = args_StartIndex + args_BinChar.length;
589
+ }
590
+ }
569
591
 
570
592
 
571
593
  let t_Index_Bin = 0;
@@ -573,11 +595,14 @@ function func_PairText
573
595
  let t_Start = 0;
574
596
 
575
597
  let t_Even_Number = false;
576
- for (; args_StartIndex < args_Length;) {
598
+ for (; args_StartIndex < args_MaxLength;) {
599
+
600
+
601
+
577
602
  t_Start = args_StartIndex;
578
603
  do {
579
604
  t_Index_End = args_Text.indexOf(args_EndChar, t_Start);
580
- if (args_EscapeChar == "" || args_EscapeChar == null) {
605
+ if (args_EscapeChar == null || args_EscapeChar == "") {
581
606
  break;
582
607
  }
583
608
  t_Even_Number = func_EscapeChar(args_Text, t_Start, t_Index_End, args_EscapeChar);
@@ -599,7 +624,7 @@ function func_PairText
599
624
  t_Start = args_StartIndex;
600
625
  do {
601
626
  t_Index_Bin = args_Text.indexOf(args_BinChar, t_Start);
602
- if (args_EscapeChar == "" || args_EscapeChar == null) {
627
+ if (args_EscapeChar == null || args_EscapeChar == "") {
603
628
  break;
604
629
  }
605
630
  t_Even_Number = func_EscapeChar(args_Text, t_Start, t_Index_Bin, args_EscapeChar);