[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

文本显示、行显、日志跟随监控工具TL.EXE

本帖最后由 happy886rr 于 2016-10-20 20:13 编辑

[Version2.0]修复7个漏洞,优化CPU占用率到3%以下,修复fgetws统计行数问题,增加强制跟随模式直接用-d开关无参数即可以进入。完全取代more、type、tail的强悍工具,支持数GB乃至TB级的超大文本,瞬间读取任意位置。代码继续精简了20行。可执行文件体积仅12KB。
下载地址:把下面图片存为a.zip解压即是。

具体用法:
  1. TL.EXE
  2. __________________________________________________________________________
  3. 完全取代more、type、tail的强悍工具,采用64位流指针,支持数GB的超大文本,
  4. 瞬间读取任意位置。
  5. 智能识别文本编码,支持定义添加任意国编码识别框架,自动判断BOM类型。原生支持
  6. ANSI、UTF8、Unicode、Unicode big endian、BIG5台湾编码。准确识别有无BOM类型、
  7. 可自定义行长、编码检测阈、跟随阈。
  8. 支持按行读取、按百分比读取。瞬移指针,无等待。 实时侦测文件末端最新行的改变,
  9. 最大可支持数TB巨型日志。时间仓促,仅在WIN7企业版32位下测试,其它系统请自行
  10. 测试、酌情试配。
  11. __________________________________________________________________________
  12. 文本显示、行显、日志跟随监控工具, 版本 2.0
  13. COPYRIGHT@2016~2018 BY HAPPY
  14. 使用:
  15. tl  [file] [-n&num1,num2]|[-p&per1,per2]|[-i]|[-d&num]
  16. __________________________________________________________________________
  17. 选项:
  18. -h    显示帮助信息
  19. -n    读取第num1行到第num2行的内容
  20. -p    按百分比读取文件内容从per1到per2,注:取值为[0,1]内的小数
  21. -i    显示文本的行数、文件大小
  22. -d    侦测文件的最新num行,静态显示
  23. -d    无参数则采取强制跟随策略,即毫秒跟随,动态显示
  24. 空    无开关则读取整个文件,支持7种编码
  25. __________________________________________________________________________
  26. 示例:
  27.          tl a.txt                      //显示a.txt文本内容;
  28.          tl a.txt -i                   //显示a.txt行数及文件大小;
  29.          tl a.txt -n3                  //从第3行读到结尾;
  30.          tl a.txt -n3,5                //从第3行读到第5行;
  31.          tl a.txt -p0.618,0.798        //显示文件的百分之几的内容
  32.          tl a.txt -d15                 //侦测文件最新15行的变动,按Q键中断
  33.          tl a.txt -d                   //强制跟随文件变动,毫秒级响应
  34. __________________________________________________________________________
复制代码
核心代码:
  1. /*
  2. DISPLAYS THE CONTENTS OF A TEXT FILE, VERSION 2.0
  3. COPYRIGHT@2016~2018 BY HAPPY
  4. */
  5. #include   <stdio.h>
  6. #include   <conio.h>
  7. #include  <locale.h>
  8. #include <stdbool.h>
  9. #include    <time.h>
  10. #include <windows.h>
  11. //定义标准行长(字节)
  12. #define BUFF_SIZE 4096
  13. //编码检测阈值(字节)
  14. #define CHECK_SIZE 16383
  15. //文件跟随阈值(行)
  16. #define FOLLOW_SIZE 1000
  17. //强制跟随行数(行)
  18. #define FOLLOW_LINE 3
  19. //跟随等待计时(毫秒)
  20. #define FOLLOW_WAIT 20
  21. /***************转码函数群***************/
  22. //Unicode 转Ansi
  23. char* UnicodeToANSI(const wchar_t* Str)
  24. {
  25. int L=WideCharToMultiByte(CP_ACP, 0, Str, -1, NULL, 0, NULL, NULL);
  26. char* Out=(char *)calloc(L+1, sizeof(char));
  27. WideCharToMultiByte(CP_ACP, 0, Str, -1, Out, L, NULL, NULL);
  28. return Out;
  29. }
  30. //UTF8 转换成 Unicode
  31. wchar_t* UTF8ToUnicode(const char* Str)
  32. {
  33. int L=MultiByteToWideChar(CP_UTF8, 0, Str,-1, NULL, 0);
  34. wchar_t* Out=(wchar_t *)calloc(L+1, sizeof(wchar_t));
  35. MultiByteToWideChar(CP_UTF8, 0, Str, -1, (LPWSTR)Out, L);
  36. return Out;
  37. }
  38. //BIG5 转换成 Unicode
  39. wchar_t* BIG5ToUnicode(const char* Str)
  40. {
  41. int L=MultiByteToWideChar(950, 0, Str,-1, NULL, 0);
  42. wchar_t* Out=(wchar_t *)calloc(L+1, sizeof(wchar_t));
  43. MultiByteToWideChar(950, 0, Str, -1, (LPWSTR)Out, L);
  44. return Out;
  45. }
  46. /***************编码检测群***************/
  47. //判断utf8无BOM
  48. bool isUTF8(const char* Str)
  49. {
  50. if(!Str){
  51. return false;
  52. }
  53. const unsigned char* bytes=(const unsigned char *)Str;
  54. while(*bytes){
  55. if(
  56. (
  57. bytes[0]<=0x7F ||
  58. bytes[0]==0x09 ||
  59. bytes[0]==0x0A ||
  60. bytes[0]==0x0D ||
  61. (0x20<=bytes[0] && bytes[0]<=0x7E)
  62. )
  63. ){
  64. bytes+=1;
  65. continue;
  66. }
  67. if(
  68. (
  69. (0xC2<=bytes[0] && bytes[0]<=0xDF) &&
  70. (0x80<=bytes[1] && bytes[1]<=0xBF)
  71. )
  72. ){
  73. bytes+=2;
  74. continue;
  75. }
  76. if(
  77. (
  78.   (bytes[0]==0xE0) &&
  79. (0xA0<=bytes[1] && bytes[1]<=0xBF) &&
  80. (0x80<=bytes[2] && bytes[2]<=0xBF)
  81. ) ||
  82. (
  83. (
  84. (0xE1<=bytes[0] && bytes[0]<=0xEC)||
  85.                    bytes[0]==0xEE ||
  86.                    bytes[0]==0xEF
  87. ) &&
  88. (0x80<=bytes[1] && bytes[1]<=0xBF) &&
  89. (0x80<=bytes[2] && bytes[2]<=0xBF)
  90. ) ||
  91. (
  92.   (bytes[0]==0xED) &&
  93. (0x80<=bytes[1] && bytes[1]<=0x9F) &&
  94. (0x80<=bytes[2] && bytes[2]<=0xBF)
  95. )
  96. ){
  97. bytes+=3;
  98. continue;
  99. }
  100. if(
  101. (
  102.   (bytes[0]==0xF0) &&
  103. (0x90<=bytes[1] && bytes[1]<=0xBF) &&
  104. (0x80<=bytes[2] && bytes[2]<=0xBF) &&
  105. (0x80<=bytes[3] && bytes[3]<=0xBF)
  106. ) ||
  107. (
  108. (0xF1<=bytes[0] && bytes[0]<=0xF3) &&
  109. (0x80<=bytes[1] && bytes[1]<=0xBF) &&
  110. (0x80<=bytes[2] && bytes[2]<=0xBF) &&
  111. (0x80<=bytes[3] && bytes[3]<=0xBF)
  112. ) ||
  113. (
  114.   (bytes[0]==0xF4) &&
  115. (0x80<=bytes[1] && bytes[1]<=0x8F) &&
  116. (0x80<=bytes[2] && bytes[2]<=0xBF) &&
  117. (0x80<=bytes[3] && bytes[3]<=0xBF)
  118. )
  119. ){
  120. bytes+=4;
  121. continue;
  122. }
  123. return false;
  124. }
  125. return true;
  126. }
  127. //判断GB2312
  128. bool isGB2312(const char* Str)
  129. {
  130. if(!Str){
  131. return false;
  132. }
  133. const unsigned char* bytes=(const unsigned char *)Str;
  134. while(*bytes){
  135. if(
  136. (
  137. bytes[0]<=0x7F ||
  138. bytes[0]==0x09 ||
  139. bytes[0]==0x0A ||
  140. bytes[0]==0x0D ||
  141. (0x20<=bytes[0] && bytes[0]<=0x7E)
  142. )
  143. ){
  144. bytes+=1;
  145. continue;
  146. }
  147. if(
  148. (0xA1<=bytes[0] && bytes[0]<=0xF7) &&
  149. (0xA1<=bytes[1] && bytes[1]<=0xFE)
  150. ){
  151. bytes+=2;
  152. continue;
  153. }
  154. return false;
  155. }
  156. return true;
  157. }
  158. /*判断BIG5*/
  159. bool isBIG5(const char* Str)
  160. {
  161. if(!Str){
  162. return false;
  163. }
  164. const unsigned char* bytes=(const unsigned char *)Str;
  165. while(*bytes){
  166. if(
  167. (
  168. bytes[0]<=0x7F ||
  169. bytes[0]==0x09 ||
  170. bytes[0]==0x0A ||
  171. bytes[0]==0x0D ||
  172. (0x20<=bytes[0] && bytes[0]<=0x7E)
  173. )
  174. ){
  175. bytes+=1;
  176. continue;
  177. }
  178. if(
  179. (0xA1<=bytes[0] && bytes[0]<=0xF9) &&
  180. (
  181. (0x40<=bytes[1] && bytes[1]<=0x7E) ||
  182. (0xA1<=bytes[1] && bytes[1]<=0xFE)
  183. )
  184. ){
  185. bytes+=2;
  186. continue;
  187. }
  188. return false;
  189. }
  190. return true;
  191. }
  192. //判断文件BOM  
  193. int CheckBom(FILE* fp)
  194. {
  195. unsigned char* buf=(unsigned char*)calloc(3,sizeof(unsigned char));
  196. unsigned char* buf2;
  197. fseeko64(fp, (__int64)0, SEEK_SET);
  198. fread(buf, sizeof(unsigned char), 3, fp);
  199.      if(buf[0]==0xEF && buf[1]==0xBB && buf[2]==0xBF){return 3;}
  200. else if(buf[0]==0xFF && buf[1]==0xFE){return 5;}
  201. else if(buf[0]==0xFE && buf[1]==0xFF){return 6;}
  202. else{
  203. fseeko64(fp, (__int64)0, SEEK_SET);
  204. buf2=(unsigned char*)calloc(CHECK_SIZE,sizeof(unsigned char));
  205. fread(buf2, sizeof(unsigned char), CHECK_SIZE, fp);
  206. if(isUTF8(buf2)){
  207. return 2;
  208. }else if(isGB2312(buf2)){
  209. return 1;
  210. }else if(isBIG5(buf2)){
  211. return 4;
  212. }
  213. }
  214. return 1;
  215. }
  216. /***************功能函数群***************/
  217. //帮助信息
  218. void Help_Information(FILE* stream, int Exit_Code)
  219. {
  220. fprintf(stream,
  221. ">>>------------------------------------------------------------\n"
  222. "DISPLAYS THE CONTENTS OF A TEXT FILE\n"
  223. "VERSION 2.0\n"
  224. "tl  [file] [-n&num1,num2]|[-p&per1,per2]|[-i]|[-d&num]\n"
  225. "---------------------------------------------------------------\n\n"
  226. "    -h  Show help information\n"
  227. "    -n  Read lines from num1 to num2\n"
  228. "    -p  Read lines from percent1 to percent2\n"
  229. "    -i  Show file's information\n"
  230. "    -d  Detection latest num lines \n"
  231. "------------------------------------------------------------<<<\n"
  232. "                                                  10/19/2016\n"
  233. );
  234. exit(Exit_Code);
  235. }
  236. //按键函数
  237. int Getkey(int N,int T)
  238. {
  239. int i,KEY_V,start=clock();
  240. do{
  241. if(kbhit()){
  242. KEY_V=(int)(getch());
  243. if(KEY_V<97){KEY_V+=32;}
  244. return KEY_V;
  245. }
  246. for(i=0;i<=N;i++);
  247. }while((clock()-start)<T);
  248. return -1;
  249. }
  250. //行数统计
  251. int CountLines(FILE* fp)
  252. {
  253. int i=0;
  254. char* line=(char *)malloc(BUFF_SIZE*sizeof(char));
  255. while(!feof(fp)){
  256. fgets(line, BUFF_SIZE, fp);
  257. i++;
  258. }
  259. return i;
  260. }
  261. //文件信息
  262. void File_Information(FILE* fp, char* fname)
  263. {
  264. fseeko64(fp, (__int64)0, SEEK_END);
  265. __int64 fsize=ftello64(fp);
  266. fseeko64(fp, (__int64)0, SEEK_SET);
  267. int linenum=CountLines(fp);
  268. fprintf(stdout,
  269. "FILE NAME : %s\n"
  270. "FILE SIZE : %I64d\n"
  271. "FILE LINES: %d\n"
  272. ,fname, fsize, linenum
  273. );
  274. }
  275. //行显函数
  276. int DisplayLine(FILE* fp, int flag, int N1, int N2, __int64 F1, __int64 F2)
  277. {
  278. int i=0, n=0, BOM=0, EN=0;
  279. //设定BOM偏移值
  280. BOM=CheckBom(fp);
  281. if(BOM==1 || BOM==2 || BOM==4){
  282. EN=0;
  283. }else if(BOM==5 || BOM==6){
  284. EN=2;
  285. }else if(BOM==3){
  286. EN=3;
  287. }
  288. //设定模式偏移量
  289. if      (flag==0){
  290. fseeko64(fp, (__int64)EN, SEEK_SET);
  291. }else if(flag==1||flag==3){
  292. __int64 FD=(N1*BUFF_SIZE>F2)?F2:N1*BUFF_SIZE;
  293. fseeko64(fp, -FD, SEEK_END);
  294. N1=CountLines(fp)-N1+1;
  295. fseeko64(fp, -FD, SEEK_END);
  296. }else if(flag==2){
  297. fseeko64(fp,  F1, SEEK_SET);
  298. }
  299. if(BOM<5){
  300. char* Line=(char *)malloc(BUFF_SIZE*sizeof(char));
  301. while(!feof(fp)||flag==3){
  302. memset(Line, 0, BUFF_SIZE*sizeof(char));
  303. if(!fgets(Line, BUFF_SIZE, fp)){Sleep(1);}
  304. i++;
  305. if( ((N1<=i) && (i<=N2) && (F1<=ftello64(fp)) && (ftello64(fp)<=F2))||(flag==3) ){
  306. switch(BOM){
  307. case 1: //Ansi行显
  308. fputs(Line, stdout);
  309. break;
  310. case 2: //Utf8无BOM行显
  311. case 3: //Utf8行显
  312. fputs(UnicodeToANSI(UTF8ToUnicode(Line)), stdout);
  313. break;
  314. case 4: //Big5行显
  315. fputs(UnicodeToANSI(BIG5ToUnicode(Line)), stdout);
  316. break;
  317. }
  318. }else if((i>N2) && (ftello64(fp)>=F2)){
  319. break;
  320. }
  321. }
  322. }else if(BOM==5){               //Unicode行显
  323. wchar_t* LineW=(wchar_t *)calloc(BUFF_SIZE, sizeof(wchar_t));
  324. while(!feof(fp)||(flag==3)){
  325. memset(LineW, 0, BUFF_SIZE*sizeof(wchar_t));
  326. if(!fgetws(LineW, BUFF_SIZE, fp)){Sleep(1);}
  327. i++;
  328. if( ((N1<=i) && (i<=N2) && (F1<=ftello64(fp)) && (ftello64(fp)<=F2))||(flag==3) ){
  329. fputs(UnicodeToANSI(LineW), stdout);
  330. }else if((i>N2) && (ftello64(fp)>=F2)){
  331. break;
  332. }
  333. }
  334. }else if(BOM==6){               //Unicode big endian行显
  335. wchar_t* LineW=(wchar_t *)calloc(BUFF_SIZE, sizeof(wchar_t));
  336. while(!feof(fp)||(flag==3)){
  337. memset(LineW, 0, BUFF_SIZE*sizeof(wchar_t));
  338. if(!fgets(LineW, BUFF_SIZE, fp)){Sleep(1);}
  339. i++;
  340. if( ((N1<=i) && (i<=N2+1) && (F1<=ftello64(fp)) && (ftello64(fp)<=F2))||(flag==3) ){
  341. for(n=0;LineW[n]!=0x0000;n++){
  342. LineW[n]=(LineW[n]&0x00FF)<<8|(LineW[n]&0xFF00)>>8;
  343. }
  344. fputs(UnicodeToANSI(LineW), stdout);
  345. }else if((i>N2) && (ftello64(fp)>=F2)){
  346. break;
  347. }
  348. }
  349. }
  350. fflush(stdout);
  351. return 0;
  352. }
  353. /*************MAIN主函数入口*************/
  354. int main(int argc, char** argv)
  355. {
  356. int N1=1, N2=2147483631, FLAG=0, i;
  357. __int64 fsize=0;
  358. float P1=0.0, P2=1.0;
  359. FILE* fp;
  360. char* delims;
  361. if((argc==3) && (argv[2][0]=='-')){
  362. switch(argv[2][1]){
  363. case 'H':
  364. case 'h':
  365. Help_Information(stdout, 0);
  366. case 'N':
  367. case 'n':
  368. delims=(argv[2]+2);
  369. N1=atoi(strtok(delims, ","));
  370. N2=atoi(strtok(NULL, ","));
  371. if(N2==0){N2=2147483631;}
  372. if((N1>N2) || (N1<0) || (N2<0)){Help_Information(stderr, 1);}
  373. break;
  374. case 'P':
  375. case 'p':
  376. delims=(argv[2]+2);
  377. P1=atof(strtok(delims, ","));
  378. P2=atof(strtok(NULL, ","));
  379. if((P1>=P2) || (P1>1.0) || (P2>1.0) || (P1<0.0) || (P2<0.0) ){Help_Information(stderr, 1);}
  380. FLAG=2;
  381. break;
  382. case 'I':
  383. case 'i':
  384. if( (fp=fopen64(argv[1], "rb"))==NULL ){fputs("Read failed.", stdout);return 3;}
  385. File_Information(fp, argv[1]);
  386. fclose(fp);
  387. return 0;
  388. case 'D':
  389. case 'd':
  390. delims=(argv[2]+2);
  391. N1=abs(atoi(delims)), N1=(N1>FOLLOW_SIZE)?1000:N1, FLAG=1;
  392. if(argv[2][2]=='\0'){N1=FOLLOW_LINE,FLAG=3;}
  393. break;
  394. default:
  395. Help_Information(stderr, 2);
  396. }
  397. }else if(argc!=2){
  398. Help_Information(stderr, 3);
  399. }
  400. if( (fp=fopen64(argv[1], "rb"))==NULL ){
  401. fputs("Read failed.", stdout);
  402. return 3;
  403. }
  404. if(FLAG==1){
  405. do{
  406. fseeko64(fp, (__int64)0, SEEK_END);
  407. if( fsize!=ftello64(fp)){
  408. fsize =ftello64(fp);
  409. system("cls");
  410. DisplayLine(fp, 1, N1, 2147483631, 0, fsize);
  411. }
  412. }while(Getkey(64,FOLLOW_WAIT)!=113);
  413. fputs("\n", stdout);
  414. fclose(fp);
  415. return 0;
  416. }
  417. fseeko64(fp, (__int64)0, SEEK_END);
  418. fsize=ftello64(fp);
  419. DisplayLine(fp, FLAG, N1, N2, fsize*P1, fsize*P2);
  420. fclose(fp);
  421. return 0;
  422. }
复制代码
_____________
_____________
______________________________________________________________________________________________________________
同时发布tl的精简版minitl仅3KB大小,迷你版minitl只支持utf8和ansi编码,速度快,支持取负行,是more和type的替代品。

minitl的用法:
提取文本文件filename的第n行到第m行
  1. tl [filename] [n] [m]
复制代码
只提取第n行
  1. minitl [filename] [n]
复制代码
提取倒数第3行
  1. minitl [filename] -3
复制代码
提取第5行到文件结束
  1. minitl [filename] 5 -1
复制代码
base64加权压缩码。
  1. @echo off
  2. ::******Happy's 文本工具 minitl.exe******
  3. set "LINE=TVqQ[M]E]//8[Lg{AQ_{][Ag]A4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJ{ABQRQ[TAEC}AO[DwMLAQY}AYBU]Q]I]AB]Q]Ag[B{[E{[Aw]Ag[NQwB[M][B[AB][E[AE{B{][ACAg[A8$_{][BcI[AX_]C50ZXh0]UAc]Q]C]AI}[C[AGAuZGF0YQ[ACAC]I]AQ]K}[B[AD${[ABVieWB7Ag[ACQu]ABQu]ABQu]ABQu]ABQuP////9Qi0UIULg]AULg]AUOhzBg[iUX4i0X4QLkB]UVDoaAY[IPECIlF/Lg]AULg]AUItF+FCLRfxQuP////9Qi0UIULg]AULg]AUOgrBg[i0X86Q]DJw1WJ5YHsC]JC4]AFC4]AFC4/////1CLRQhQu]ABQuOn9[BQ6[G[CJRfyLRfxAuQI[ABRUOjlBQ[g8QIiUX4i0X8UItF+FC4/////1CLRQhQu]ABQuOn9[BQ6MQF[CLRfjp]AMnDVYnlgewI]kLg]AiUX8u]ABQi0UYUItFCFDonQU[IPEDItFCFDomQU[IPEBIXAD4QF]6dg[AC4AQ[AFC4AB[AFDoYAU[IPECIlF+ItFCFC4AB[AFCLRfhQ6GcF[CDxAyFwA+Eng[AItF/InBQIlF/ItFDIXAD4QF]6YU[ACLRfyLTRA5yA+Mdw[AItF/ItNFDnID44K]uP/////pjQ[AItFGIXAD4QF]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HRlcg[AF9leGl0]X2V4Y2VwdF9oYW5kbGVyMw@#}A="
  4. ::******Base64加权解密器*************
  5. setlocal enabledelayedexpansion
  6. set "Z=A"&(for %%Z in ([,],{,},_,$,#,-,@) do (set "Z=!Z!!Z!"&for %%S in (!Z!) do (set "LINE=!LINE:%%Z=%%S!")))&echo !LINE:.=!>base64_minitl
  7. certutil -decode base64_minitl minitl.exe
复制代码
4

评分人数

真牛           ~
判定一个人是否为伸手党的标准是取决于他的态度和诚意。

TOP

4096把长行拆成几行了,classpath超出你相信

TOP

卧槽,史上最快版本迭代

TOP

  1. ::******Base64加权解密器*************
  2. setlocal enabledelayedexpansion
  3. set "Z=A"&(for %%Z in ([,],{,},_,$,#,-,@) do (set "Z=!Z!!Z!"&for %%S in (!Z!) do (set "LINE=!LINE:%%Z=%%S!")))&echo !LINE:.=!>base64_minitl
复制代码
压缩前 4780 个字符,压缩后 2859 个字符,压缩了 40.19% 。
这算法很好,可惜看不懂。
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

本帖最后由 happy886rr 于 2016-10-20 21:28 编辑

回复 5# yu2n
加权,谁的权重大,就优先压缩谁。层层嵌套,这只是一层,只压了40%,如果是3层,可以实现体积减少80%,不过得携带通用解压字典。类似过去的电报译码表。经过几次测试,这种算法的有点经常超越7Z的压缩率。要想压得狠,就得带字典。

比如论坛代码遇到g c d这几个组合就会被吃掉,所以可以把**定义为一个字母,总之给一些常用的组合编码,制作成码表,解压的时候根据码表重组。就好比基因工程,基因决定了你的生物性状,但基因只是压缩的编码,生物是由基因调度氨基酸组合成蛋白质构成细胞结构体。这也是仿生学。
1

评分人数

TOP

回复 5# yu2n

可以想象成俄罗斯套娃

TOP

本帖最后由 CrLf 于 2016-10-20 23:21 编辑

回复 6# happy886rr


    效果很好,尤其是 EXE 的 Base64,但是目前只适用于 A,若要扩展到其他字符,如何区分不同的层?

TOP

本帖最后由 CrLf 于 2016-10-20 23:34 编辑

附顶楼压缩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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
  4. setlocal enabledelayedexpansion
  5. set "Z=A"
  6. for %%Z in (@,-,#,$,_,},{,],[) do (
  7. for %%S in (!Z!) do (
  8. set "LINE=!LINE:%%S%%S=%%Z!"
  9. )
  10. set "Z=%%Z"
  11. )
  12. echo !LINE!
  13. pause
复制代码

TOP

回复 9# CrLf
小写aa会被干掉吗?

TOP

回复 10# happy886rr


    是哦,我怎么没想到

TOP

TL的bug ,unicode 无BOM头识别失败
判定一个人是否为伸手党的标准是取决于他的态度和诚意。

TOP

回复 12# wskwfkbdn
unicode和unicode big endian一般是靠bom来区分字节序的。如果没有bom,你可以直接在tl的C代码的编码检测群中添加一个函数,检测00 0A或0A 00。从而判断大小端。
  1. /*判断大小端*/
  2. int isUnicode(const char* Str)
  3. {
  4. if(!Str){
  5. return false;
  6. }
  7. const unsigned char* bytes=(const unsigned char *)Str;
  8. while(*bytes){
  9. if(bytes[0]==0x00 && bytes[1]==0x0A){
  10. return 1;  //小端
  11. }else if(bytes[0]==0x0A && bytes[1]==0x00){
  12. return 2;  //大端
  13. }
  14. bytes+=2;
  15. }
  16. return 0;                  //除非这个文本一个换行符都没有
  17. }
复制代码

TOP

本帖最后由 523066680 于 2016-10-24 10:03 编辑

回复 11# CrLf

   《Why didn't I think of that》

TOP

回复 13# happy886rr

0D 00 0A 00
如果没有呢,就不好判断了吧
判定一个人是否为伸手党的标准是取决于他的态度和诚意。

TOP

返回列表