37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名:String.nut
 | |
| 路径:Core/BaseTool/String.nut
 | |
| 创建日期:2024-11-28	23:05
 | |
| 文件用途:
 | |
| */
 | |
| class String {
 | |
| 
 | |
|     //将含有../的路径转为真实路径
 | |
|     function RegRealPath(Path) {
 | |
|         if (Path.find("../") != null) {
 | |
|             while (true) {
 | |
|                 local rbuf = regexp("[^/]+/../");
 | |
|                 local Ret = rbuf.capture(Path);
 | |
|                 if (Ret) {
 | |
|                     Path = Path.slice(0, Ret[0].begin) + Path.slice(Ret[0].end);
 | |
|                 } else {
 | |
|                     return Path;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         return Path;
 | |
|     }
 | |
| 
 | |
|     function ReplaceString(input, pattern, replacement) {
 | |
|         local rbuf = typeof pattern == "string" ? regexp(pattern) : pattern;
 | |
|         while (true) {
 | |
|             local result = rbuf.capture(input);
 | |
|             if (!result) break;
 | |
| 
 | |
|             local begin = result[0].begin;
 | |
|             local end = result[0].end;
 | |
|             input = input.slice(0, begin) + replacement + input.slice(end);
 | |
|         }
 | |
|         return input;
 | |
|     }
 | |
| } |