mingyang_text 2023.5.18 → 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 +6 -5
  3. package/text.js +193 -1
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.05.18",
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",
@@ -18,7 +16,10 @@
18
16
  "time/uuid",
19
17
  "base62",
20
18
  "baseX",
21
- "any base system"
19
+ "any base system",
20
+ "string pair",
21
+ "char pair",
22
+ "text pair"
22
23
  ],
23
24
  "author": "wang.fu.jun@qq.com,wang.ming.yang@126.com",
24
25
  "license": "ISC"
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
  * 对【数字】或【字符】进行【左侧补齐】操作
@@ -484,4 +496,184 @@ function func_Byte_Truncate(args_InputString, args_ByteLength, args_Encoding = "
484
496
  }
485
497
  return temp_Description;
486
498
  }
487
- module.exports.do_Byte_Truncate = func_Byte_Truncate;
499
+ module.exports.do_Byte_Truncate = func_Byte_Truncate;
500
+
501
+
502
+
503
+
504
+
505
+ /**
506
+ * 找到配对的坐标,匹配不上的时候返回-1
507
+ * @param {"目标文本,例如【json串】"} args_Text
508
+ * @param {"右侧的限度位置"} args_LimitIndex
509
+ * @param {"当前字符的位置"} args_CurrentIndex
510
+ * @param {"转义字符,例如【\】"} args_EscapeChar
511
+ */
512
+ function func_EscapeChar
513
+ (
514
+ /*目标文本*/ args_Text
515
+ , /*限度位置*/ args_LimitIndex
516
+ , /*当前位置*/ args_CurrentIndex
517
+ , /*转义字符*/ args_EscapeChar
518
+ ) {
519
+ let temp_Amount = 0;
520
+ let temp_Char = "";
521
+ do {
522
+ args_CurrentIndex = args_CurrentIndex - 1;
523
+ if (args_CurrentIndex >= args_LimitIndex) {//如果向前一位置,仍然小于开始位置
524
+ temp_Char = args_Text.substring(args_CurrentIndex, args_CurrentIndex + 1);
525
+ if (temp_Char == args_EscapeChar) {//记录一次
526
+ temp_Amount++;
527
+ }
528
+ else {// 否则:停止
529
+ break;
530
+ }
531
+ }
532
+ else {//否则:停止
533
+ break;
534
+ }
535
+ } while (true);
536
+
537
+ return (temp_Amount % 2) == 0;
538
+ }
539
+ module.exports.do_EscapeChar = func_EscapeChar;
540
+
541
+
542
+
543
+
544
+
545
+ /**
546
+ * 返回一个数组,下标0:配对的坐标;下标1:缺失的结束文本个数;匹配不到的时候下标0为【-1】
547
+ * @param {"目标文本,例如【json串】"} args_Text
548
+ * @param {"开始文本,例如【(<】"} args_BinChar
549
+ * @param {"结束文本,例如【)>】"} args_EndChar
550
+ * @param {"开始位置,应是开始文本的下一位"} args_StartIndex
551
+ * @param {"查找范围,通常是目标文本的长度"} args_MaxLength
552
+ * @param {"转义字符,例如【\\】"} args_EscapeChar
553
+ */
554
+ function func_PairText
555
+ (
556
+ /*要处理的目标字符串*/ args_Text
557
+ , /*开始字符例如【{[】*/ args_BinChar
558
+ , /*结束字符例如【}]】*/ args_EndChar
559
+ , /*应该是起始字符的位置+1*/ args_StartIndex = 0
560
+ , /*一般是输入字符的length*/ args_MaxLength = 0
561
+ , /*转义字符例如【\\】*/ args_EscapeChar = null
562
+ ) {
563
+
564
+ //起步就是1个
565
+ args_Missing = 1;
566
+
567
+ if (args_EndChar == "") {//如果【结束符】是空,那么直接返回最后的位置
568
+ return [args_Text.length, args_Missing];
569
+ }
570
+
571
+
572
+
573
+
574
+ if (args_BinChar == "") {//如果【开始符】是空,那么直接返回【结束符】的位置
575
+ return [args_Text.indexOf(args_EndChar, args_StartIndex), args_Missing];
576
+ }
577
+
578
+
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
+ }
591
+
592
+
593
+ let t_Index_Bin = 0;
594
+ let t_Index_End = 0;
595
+ let t_Start = 0;
596
+
597
+ let t_Even_Number = false;
598
+ for (; args_StartIndex < args_MaxLength;) {
599
+
600
+
601
+
602
+ t_Start = args_StartIndex;
603
+ do {
604
+ t_Index_End = args_Text.indexOf(args_EndChar, t_Start);
605
+ if (args_EscapeChar == null || args_EscapeChar == "") {
606
+ break;
607
+ }
608
+ t_Even_Number = func_EscapeChar(args_Text, t_Start, t_Index_End, args_EscapeChar);
609
+
610
+ /**
611
+ * 只能加1,不能加p_EndChar.length
612
+ * 案例:
613
+ * 字符串="aaa0123456\tttt"
614
+ * 开始符="aaa"
615
+ * 结束符="ttt"
616
+ * 转义符="\"
617
+ */
618
+ t_Start = t_Index_End + 1;
619
+ }
620
+ while (false == t_Even_Number);
621
+
622
+
623
+
624
+ t_Start = args_StartIndex;
625
+ do {
626
+ t_Index_Bin = args_Text.indexOf(args_BinChar, t_Start);
627
+ if (args_EscapeChar == null || args_EscapeChar == "") {
628
+ break;
629
+ }
630
+ t_Even_Number = func_EscapeChar(args_Text, t_Start, t_Index_Bin, args_EscapeChar);
631
+
632
+ /**
633
+ * 只能加1,不能加p_EndChar.length
634
+ * 案例:
635
+ * 字符串="aaa0123456\tttt"
636
+ * 开始符="aaa"
637
+ * 结束符="ttt"
638
+ * 转义符="\"
639
+ */
640
+ t_Start = t_Index_Bin + 1;
641
+ }
642
+ while (false == t_Even_Number);
643
+
644
+
645
+
646
+
647
+
648
+
649
+ if (t_Index_End == -1) {
650
+ return [-1, args_Missing];
651
+ }
652
+ else {
653
+ if (t_Index_Bin > -1) {
654
+ if (t_Index_End <= t_Index_Bin)//对于【开始符】和【结束符】一样的时候【结束符】优先
655
+ {
656
+ args_Missing--;
657
+ args_StartIndex = t_Index_End + args_EndChar.length;
658
+ }
659
+ else {
660
+ args_Missing++;
661
+ args_StartIndex = t_Index_Bin + args_BinChar.length;
662
+ }
663
+ }
664
+ else {
665
+ {
666
+ args_Missing--;
667
+ args_StartIndex = t_Index_End + args_EndChar.length;
668
+ }
669
+ }
670
+ }
671
+
672
+
673
+ if (args_Missing == 0) {
674
+ return [t_Index_End, args_Missing];
675
+ }
676
+ }
677
+ return [-1, args_Missing];
678
+ }
679
+ module.exports.do_PairText = func_PairText;