funcs.tin 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #nop ############################ 小工具-方向处理 #################################;
  2. #function {reverseCmds} {
  3. #local cmds {%1};
  4. #local newCmds {};
  5. #foreach {$cmds} {item} {
  6. #format {newCmds} {%s;%s} @reverseDir{$item} {$newCmds};
  7. };
  8. #return {$newCmds};
  9. };
  10. #function {dirName} { #return @convertDir{name; %1; %2}; };
  11. #function {shortDir} { #return @convertDir{short; %1; %2}; };
  12. #function {longDir} { #return @convertDir{long; %1; %2}; };
  13. #function {reverseDir} { #return @convertDir{reverse; %1; %2}; };
  14. #var xtt.dir.table {
  15. {east} {{name}{正东} {short}{e} {long}{east} {reverse}{west} }
  16. {west} {{name}{正西} {short}{w} {long}{west} {reverse}{east} }
  17. {south} {{name}{正南} {short}{s} {long}{south} {reverse}{north} }
  18. {north} {{name}{正北} {short}{n} {long}{north} {reverse}{south} }
  19. {e} {{name}{正东} {short}{e} {long}{east} {reverse}{w} }
  20. {w} {{name}{正西} {short}{w} {long}{west} {reverse}{e} }
  21. {s} {{name}{正南} {short}{s} {long}{south} {reverse}{n} }
  22. {n} {{name}{正北} {short}{n} {long}{north} {reverse}{s} }
  23. {northeast} {{name}{东北} {short}{ne} {long}{northeast} {reverse}{southwest}}
  24. {southeast} {{name}{东南} {short}{se} {long}{southeast} {reverse}{northwest}}
  25. {northwest} {{name}{西北} {short}{nw} {long}{northwest} {reverse}{southeast}}
  26. {southwest} {{name}{西南} {short}{sw} {long}{southwest} {reverse}{northeast}}
  27. {ne} {{name}{东北} {short}{ne} {long}{northeast} {reverse}{sw} }
  28. {se} {{name}{东南} {short}{se} {long}{southeast} {reverse}{nw} }
  29. {nw} {{name}{西北} {short}{nw} {long}{northwest} {reverse}{se} }
  30. {sw} {{name}{西南} {short}{sw} {long}{southwest} {reverse}{ne} }
  31. {up} {{name}{正上} {short}{u} {long}{up} {reverse}{down} }
  32. {down} {{name}{正下} {short}{d} {long}{down} {reverse}{up} }
  33. {u} {{name}{正上} {short}{u} {long}{up} {reverse}{d} }
  34. {d} {{name}{正下} {short}{d} {long}{down} {reverse}{u} }
  35. {eastup} {{name}{东上} {short}{eu} {long}{eastup} {reverse}{westdown} }
  36. {westup} {{name}{西上} {short}{wu} {long}{westup} {reverse}{eastdown} }
  37. {southup} {{name}{南上} {short}{su} {long}{southup} {reverse}{northdown}}
  38. {northup} {{name}{北上} {short}{nu} {long}{northup} {reverse}{southdown}}
  39. {eu} {{name}{东上} {short}{eu} {long}{eastup} {reverse}{wd} }
  40. {wu} {{name}{西上} {short}{wu} {long}{westup} {reverse}{ed} }
  41. {su} {{name}{南上} {short}{su} {long}{southup} {reverse}{nd} }
  42. {nu} {{name}{北上} {short}{nu} {long}{northup} {reverse}{sd} }
  43. {eastdown} {{name}{东下} {short}{ed} {long}{eastdown} {reverse}{westup} }
  44. {westdown} {{name}{西下} {short}{wd} {long}{westdown} {reverse}{eastup} }
  45. {southdown} {{name}{南下} {short}{sd} {long}{southdown} {reverse}{northup} }
  46. {northdown} {{name}{北下} {short}{nd} {long}{northdown} {reverse}{southup} }
  47. {ed} {{name}{东下} {short}{ed} {long}{eastdown} {reverse}{wu} }
  48. {wd} {{name}{西下} {short}{wd} {long}{westdown} {reverse}{eu} }
  49. {sd} {{name}{南下} {short}{sd} {long}{southdown} {reverse}{nu} }
  50. {nd} {{name}{北下} {short}{nd} {long}{northdown} {reverse}{su} }
  51. {out} {{name}{出去} {short}{out} {long}{out} {reverse}{enter} }
  52. {enter} {{name}{进去} {short}{enter} {long}{enter} {reverse}{out} }
  53. };
  54. #function {convertDir} {
  55. #local field {%1};
  56. #local dir {%2};
  57. #local restricted {%2};
  58. #if { "$dir" == "" } {
  59. #return "";
  60. };
  61. #local entry ${xtt.dir.table[$dir]};
  62. #if { "$restricted" == "true" && "$entry" == "" } {
  63. #return {};
  64. };
  65. #else {
  66. #return {$entry[$field]};
  67. };
  68. };
  69. #nop ############################ 小工具-语法增强 #################################;
  70. #function {boolAnd} {
  71. #if { "%1" == "true" && "%2" == "true" } {
  72. #return {true};
  73. };
  74. #return {false};
  75. };
  76. #function {reverseList} {
  77. #var l {%1};
  78. #list {l} size len;
  79. #list {result} create {};
  80. #loop $len 1 {idx} {
  81. #list {result} add $l[$idx];
  82. };
  83. };
  84. #function {eval} {#math result {%1}};
  85. #function {space} {#var result {@repeat{%1;{ }}}};
  86. #function {repeat} {#var result {}; #loop 1 %1 tmp {#var result {${result}%2}}};
  87. #function {string2list} {#list result {create} {%1}};
  88. #function {list2string} {#var l {%1}; #list l simplify; #return {$l}};
  89. #function {strListSize} {#list l create {%1}; #list l size result};
  90. #function {indexOfStrList} {#list l create {%1}; #list l find {%2} result};
  91. #function {indexOf} {#var l {%1}; #list l find {%2} result};
  92. #function {trim} {#format {result} {%p} {%1}};
  93. #function {trimAll} {#var result {%1}; #replace {result} { } {}};
  94. #function {sort} {#var l {%0}; #var result {}; #foreach {$l} {tmp} {#list result {sort} {$tmp}}; #return {@list2string{{$result}}}};
  95. #function {sortList} {#var l {@list2string{{%0}}}; #var result {}; #foreach {$l} {tmp} {#list result {sort} {$tmp}}};
  96. #function {listSize} {#var l {%1}; #list l size result};
  97. #function {listSet} {#var l {%1}; #loc idx {%2}; #loc data {%3}; #var l @listExtend{{$l};$idx}; #list l set {$idx} {$data}; #return {$l} };
  98. #function {listExtend} {#var l {%1}; #loc len {%2}; #loc size {@listSize{{$l}}}; #math len {$len - $size}; #if { $len > 0 } { #loop {1} {$len} {id} { #list l add {{}} } }; #return {$l} };
  99. #function {len} {#format result {%L} {%1}};
  100. #function {toLower} {#format result {%l} {%1}};
  101. #function {capital} {#format result {%n} {%1}};
  102. #function {replace} {#var result %1;#replace result {%2} {%3}};
  103. #function {inList} {#math result { @indexOf{{%1};{%2}} > 0 }};
  104. #function {center} {#format len {%L} {%1}; #math left {(%2 - $len) / 2 + $len}; #math right {%2 - $left}; #format result {%${left}s%${right}s} {%1} {}};
  105. #function {max} {#var result {%1}; #foreach {%0} {i} {#if { $i > $result} { #var result {$i}}}};
  106. #function {min} {#var result {%1}; #foreach {%0} {i} {#if { $i < $result} { #var result {$i}}}};
  107. #function {parseTime} {
  108. #local {timeStr} {%1};
  109. #nop 注意这里用了个小技巧,末尾的空格不要去掉;
  110. #replace timeStr {%S小时} {@c2d{&1}*3600+ };
  111. #replace timeStr {%S分} {@c2d{&1}*60+ };
  112. #replace timeStr {%S秒} {@c2d{&1}};
  113. #local time {};
  114. #math time {$timeStr + 0};
  115. #return {$time};
  116. };
  117. #function {c2d} {
  118. #local string {%1};
  119. #local number1 {};
  120. #local number2 {0};
  121. #local number3 {0};
  122. #local chr {};
  123. #local ch {};
  124. #parse {$string} {ch} {
  125. #if { "$ch" == "{1|2|3|4|5|6|7|8|9|0|\.}" } {
  126. #format number1 {%s%s} {$number1} {$ch};
  127. #continue;
  128. };
  129. #switch {"$ch"} {
  130. #case {"零"} { #format number1 {0} };
  131. #case {"一"} { #format number1 {1} };
  132. #case {"二"} { #format number1 {2} };
  133. #case {"三"} { #format number1 {3} };
  134. #case {"四"} { #format number1 {4} };
  135. #case {"五"} { #format number1 {5} };
  136. #case {"六"} { #format number1 {6} };
  137. #case {"七"} { #format number1 {7} };
  138. #case {"八"} { #format number1 {8} };
  139. #case {"九"} { #format number1 {9} };
  140. #case {"十"} {
  141. #if { "$number1" == "" } {
  142. #format number1 {1};
  143. };
  144. #math number2 {$number2 + $number1 * 10};
  145. #format number1 {};
  146. };
  147. #case {"百"} {
  148. #math number2 {$number2 + $number1 * 100};
  149. #format number1 {};
  150. };
  151. #case {"千"} {
  152. #math number2 {$number2 + $number1 * 1000};
  153. #format number1 {};
  154. };
  155. #case {"万"} {
  156. #math number3 {($number2 + $number1) * 10000};
  157. #format number1 {};
  158. #format number2 {0};
  159. };
  160. #case {"亿"} {
  161. #math number3 {($number2 + $number1) * 100000000};
  162. #format number1 {};
  163. #format number2 {0};
  164. };
  165. };
  166. };
  167. #if { "$number1" == "" } {
  168. #format number1 {0};
  169. };
  170. #local number {};
  171. #math number {$number1 + $number2 + $number3};
  172. #return $number;
  173. };
  174. #function {strWidth} {
  175. #local str {%1};
  176. #replace {str} {<{[gG0-9A-Fa-f]{1,8}}>} {};
  177. #replace {str} {{\e\[[0-9;]+m}} {};
  178. #return {@len{$str}};
  179. };