mingyang_text 2023.2.24 → 2023.6.3
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.
- package/package.json +5 -2
- package/text.js +196 -5
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mingyang_text",
|
3
|
-
"version": "2023.
|
3
|
+
"version": "2023.06.03",
|
4
4
|
"description": "MingYang Packet",
|
5
5
|
"main": "text.js",
|
6
6
|
"scripts": {
|
@@ -18,7 +18,10 @@
|
|
18
18
|
"time/uuid",
|
19
19
|
"base62",
|
20
20
|
"baseX",
|
21
|
-
"any base system"
|
21
|
+
"any base system",
|
22
|
+
"string pair",
|
23
|
+
"char pair",
|
24
|
+
"text pair"
|
22
25
|
],
|
23
26
|
"author": "wang.fu.jun@qq.com,wang.ming.yang@126.com",
|
24
27
|
"license": "ISC"
|
package/text.js
CHANGED
@@ -305,22 +305,46 @@ module.exports.do_KeyValue_Decode = func_KeyValue_Decode;
|
|
305
305
|
* @param {"源数据包"} args_Datas
|
306
306
|
* @param {"分割字符"} args_Split
|
307
307
|
* @param {"等于字符"} args_Equal
|
308
|
+
* @param {"是否编码"} args_EncodeUriComponent
|
309
|
+
* @param {"是否排序"} args_Sort
|
308
310
|
*/
|
309
|
-
function func_KeyValue_Encode(args_Datas, args_Split, args_Equal) {
|
311
|
+
function func_KeyValue_Encode(args_Datas, args_Split, args_Equal, args_EncodeUriComponent = true, args_Sort = false) {
|
310
312
|
|
311
313
|
let temp_Keys = Object.keys(args_Datas);
|
314
|
+
if (true == args_Sort) {
|
315
|
+
temp_Keys.sort();
|
316
|
+
}
|
317
|
+
|
312
318
|
let t_Lenth = temp_Keys.length;
|
313
319
|
if (t_Lenth == 0) {
|
314
320
|
return "";
|
315
321
|
}
|
316
322
|
|
323
|
+
let temp_Value = "";
|
324
|
+
let temp_Line = "";
|
317
325
|
let i = 0;
|
318
|
-
|
319
|
-
|
326
|
+
|
327
|
+
{
|
328
|
+
if (true == args_EncodeUriComponent) {
|
329
|
+
temp_Value = encodeURIComponent(args_Datas[temp_Keys[i]]);
|
330
|
+
}
|
331
|
+
else {
|
332
|
+
temp_Value = args_Datas[temp_Keys[i]];
|
333
|
+
}
|
334
|
+
temp_Line = encodeURIComponent(temp_Keys[i]) + args_Equal + temp_Value;
|
335
|
+
i++;
|
336
|
+
}
|
320
337
|
|
321
338
|
for (; i < t_Lenth; i++) {
|
322
339
|
temp_Line += args_Split;
|
323
|
-
|
340
|
+
|
341
|
+
if (true == args_EncodeUriComponent) {
|
342
|
+
temp_Value = encodeURIComponent(args_Datas[temp_Keys[i]]);
|
343
|
+
}
|
344
|
+
else {
|
345
|
+
temp_Value = args_Datas[temp_Keys[i]];
|
346
|
+
}
|
347
|
+
temp_Line += encodeURIComponent(temp_Keys[i]) + args_Equal + temp_Value;
|
324
348
|
}
|
325
349
|
|
326
350
|
return temp_Line;
|
@@ -460,4 +484,171 @@ function func_Byte_Truncate(args_InputString, args_ByteLength, args_Encoding = "
|
|
460
484
|
}
|
461
485
|
return temp_Description;
|
462
486
|
}
|
463
|
-
module.exports.do_Byte_Truncate = func_Byte_Truncate;
|
487
|
+
module.exports.do_Byte_Truncate = func_Byte_Truncate;
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
/**
|
494
|
+
* 找到配对的坐标,匹配不上的时候返回-1
|
495
|
+
* @param {"目标文本,例如【json串】"} args_Text
|
496
|
+
* @param {"右侧的限度位置"} args_LimitIndex
|
497
|
+
* @param {"当前字符的位置"} args_CurrentIndex
|
498
|
+
* @param {"转义字符,例如【\】"} args_EscapeChar
|
499
|
+
*/
|
500
|
+
function func_EscapeChar
|
501
|
+
(
|
502
|
+
/*目标文本*/ args_Text
|
503
|
+
, /*限度位置*/ args_LimitIndex
|
504
|
+
, /*当前位置*/ args_CurrentIndex
|
505
|
+
, /*转义字符*/ args_EscapeChar
|
506
|
+
) {
|
507
|
+
let temp_Amount = 0;
|
508
|
+
let temp_Char = "";
|
509
|
+
do {
|
510
|
+
args_CurrentIndex = args_CurrentIndex - 1;
|
511
|
+
if (args_CurrentIndex >= args_LimitIndex) {//如果向前一位置,仍然小于开始位置
|
512
|
+
temp_Char = args_Text.substring(args_CurrentIndex, args_CurrentIndex + 1);
|
513
|
+
if (temp_Char == args_EscapeChar) {//记录一次
|
514
|
+
temp_Amount++;
|
515
|
+
}
|
516
|
+
else {// 否则:停止
|
517
|
+
break;
|
518
|
+
}
|
519
|
+
}
|
520
|
+
else {//否则:停止
|
521
|
+
break;
|
522
|
+
}
|
523
|
+
} while (true);
|
524
|
+
|
525
|
+
return (temp_Amount % 2) == 0;
|
526
|
+
}
|
527
|
+
module.exports.do_EscapeChar = func_EscapeChar;
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
/**
|
534
|
+
* 找到配对的坐标,匹配不上的时候返回-1
|
535
|
+
* @param {"目标文本,例如【json串】"} args_Text
|
536
|
+
* @param {"转义字符,例如【\\】"} args_EscapeChar
|
537
|
+
* @param {"开始文本,例如【(<】"} args_BinChar
|
538
|
+
* @param {"结束文本,例如【)>】"} args_EndChar
|
539
|
+
* @param {"开始位置,应是开始文本的下一位"} args_StartIndex
|
540
|
+
* @param {"查找范围,通常是目标文本的长度"} args_Length
|
541
|
+
*/
|
542
|
+
function func_PairText
|
543
|
+
(
|
544
|
+
/*要处理的目标字符串*/ args_Text
|
545
|
+
, /*转义字符例如【\\】*/ args_EscapeChar
|
546
|
+
, /*开始字符例如【{[】*/ args_BinChar
|
547
|
+
, /*结束字符例如【}]】*/ args_EndChar
|
548
|
+
, /*应该是起始字符的位置+1*/ args_StartIndex
|
549
|
+
, /*一般是输入字符的length*/ args_Length
|
550
|
+
) {
|
551
|
+
|
552
|
+
//起步就是1个
|
553
|
+
args_Missing = 1;
|
554
|
+
|
555
|
+
if (args_EndChar == "") {//如果【结束符】是空,那么直接返回最后的位置
|
556
|
+
return [args_Text.length, args_Missing];
|
557
|
+
}
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
|
562
|
+
if (args_BinChar == "") {//如果【开始符】是空,那么直接返回【结束符】的位置
|
563
|
+
return [args_Text.indexOf(args_EndChar, args_StartIndex), args_Missing];
|
564
|
+
}
|
565
|
+
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
|
570
|
+
|
571
|
+
let t_Index_Bin = 0;
|
572
|
+
let t_Index_End = 0;
|
573
|
+
let t_Start = 0;
|
574
|
+
|
575
|
+
let t_Even_Number = false;
|
576
|
+
for (; args_StartIndex < args_Length;) {
|
577
|
+
t_Start = args_StartIndex;
|
578
|
+
do {
|
579
|
+
t_Index_End = args_Text.indexOf(args_EndChar, t_Start);
|
580
|
+
if (args_EscapeChar == "" || args_EscapeChar == null) {
|
581
|
+
break;
|
582
|
+
}
|
583
|
+
t_Even_Number = func_EscapeChar(args_Text, t_Start, t_Index_End, args_EscapeChar);
|
584
|
+
|
585
|
+
/**
|
586
|
+
* 只能加1,不能加p_EndChar.length
|
587
|
+
* 案例:
|
588
|
+
* 字符串="aaa0123456\tttt"
|
589
|
+
* 开始符="aaa"
|
590
|
+
* 结束符="ttt"
|
591
|
+
* 转义符="\"
|
592
|
+
*/
|
593
|
+
t_Start = t_Index_End + 1;
|
594
|
+
}
|
595
|
+
while (false == t_Even_Number);
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
t_Start = args_StartIndex;
|
600
|
+
do {
|
601
|
+
t_Index_Bin = args_Text.indexOf(args_BinChar, t_Start);
|
602
|
+
if (args_EscapeChar == "" || args_EscapeChar == null) {
|
603
|
+
break;
|
604
|
+
}
|
605
|
+
t_Even_Number = func_EscapeChar(args_Text, t_Start, t_Index_Bin, args_EscapeChar);
|
606
|
+
|
607
|
+
/**
|
608
|
+
* 只能加1,不能加p_EndChar.length
|
609
|
+
* 案例:
|
610
|
+
* 字符串="aaa0123456\tttt"
|
611
|
+
* 开始符="aaa"
|
612
|
+
* 结束符="ttt"
|
613
|
+
* 转义符="\"
|
614
|
+
*/
|
615
|
+
t_Start = t_Index_Bin + 1;
|
616
|
+
}
|
617
|
+
while (false == t_Even_Number);
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
|
622
|
+
|
623
|
+
|
624
|
+
if (t_Index_End == -1) {
|
625
|
+
return [-1, args_Missing];
|
626
|
+
}
|
627
|
+
else {
|
628
|
+
if (t_Index_Bin > -1) {
|
629
|
+
if (t_Index_End <= t_Index_Bin)//对于【开始符】和【结束符】一样的时候【结束符】优先
|
630
|
+
{
|
631
|
+
args_Missing--;
|
632
|
+
args_StartIndex = t_Index_End + args_EndChar.length;
|
633
|
+
}
|
634
|
+
else {
|
635
|
+
args_Missing++;
|
636
|
+
args_StartIndex = t_Index_Bin + args_BinChar.length;
|
637
|
+
}
|
638
|
+
}
|
639
|
+
else {
|
640
|
+
{
|
641
|
+
args_Missing--;
|
642
|
+
args_StartIndex = t_Index_End + args_EndChar.length;
|
643
|
+
}
|
644
|
+
}
|
645
|
+
}
|
646
|
+
|
647
|
+
|
648
|
+
if (args_Missing == 0) {
|
649
|
+
return [t_Index_End, args_Missing];
|
650
|
+
}
|
651
|
+
}
|
652
|
+
return [-1, args_Missing];
|
653
|
+
}
|
654
|
+
module.exports.do_PairText = func_PairText;
|