scancscode 1.0.11 → 1.0.13

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.
@@ -9,6 +9,9 @@ class CSCodeScanner {
9
9
  static assignmentPattern = /([\w\.\u4e00-\u9fff]+\.text\s*=(?![=>])\s*)([^;]+)\s*;/mg;
10
10
  // 正则表达式匹配 匹配每个字符串
11
11
  static stringPattern = /\$?"([^"]*)"/mg;
12
+ // 正则表达式匹配 匹配获取成员值的表达式
13
+ static getMemberValuePattern = /\s*(?:\+\s*)?([\w\.\u4e00-\u9fff\[\]]+)(\.TR\(\))?/mg;
14
+ static memberSplit = /^[\s\+;]/;
12
15
  // 正则表达式匹配插值表达式 {...}
13
16
  static interpolationPattern = /\{([^}]+?)(\:[a-zA-Z\d-\.\#(?:\\\\:)\u4e00-\u9fff]+)?\}/mg;
14
17
  static stringFormatPattern = /(?<![a-zA-Z_\u4e00-\u9fff])([sS]tring\.Format)(?=\(.*?\))/mg;
@@ -158,7 +161,7 @@ class CSCodeScanner {
158
161
  // if ((stringStartIndex == 0 || prefix == "+ ") && suffix != ".TR()") {
159
162
  // formattedStringLine = formattedStringLine + ".TR()"
160
163
  // }
161
- formattedStringLine = this.replaceStringsTR(stringMatch, stringLine, bodyLine);
164
+ formattedStringLine = this.replaceStringsTR(stringMatch, stringLine, bodyLine, trmethodname);
162
165
  literals.push(stringContent);
163
166
  }
164
167
  convertedString = formattedStringLine;
@@ -166,7 +169,7 @@ class CSCodeScanner {
166
169
  }
167
170
  else {
168
171
  literals.push(stringContent);
169
- convertedString = this.replaceStringsTR(stringMatch, stringLine, bodyLine);
172
+ convertedString = this.replaceStringsTR(stringMatch, stringLine, bodyLine, trmethodname);
170
173
  }
171
174
  // 串联字符串列表
172
175
  let prefix = bodyLine.substring(lastIndex, stringLineIndex);
@@ -182,7 +185,26 @@ class CSCodeScanner {
182
185
  }
183
186
  }
184
187
  else {
185
- convertedAssignLine = assignLine;
188
+ const memberMatchs = [...bodyLine.matchAll(CSCodeScanner.getMemberValuePattern)];
189
+ if (memberMatchs.length == 1) {
190
+ let match1 = memberMatchs[0];
191
+ let c2 = bodyLine.substring(match1.index + match1[0].length);
192
+ if (c2 != '' && c2.match(CSCodeScanner.memberSplit) == null) {
193
+ memberMatchs.length = 0;
194
+ }
195
+ }
196
+ if (memberMatchs.length > 0) {
197
+ let memberLines = [];
198
+ for (let i = 0; i < memberMatchs.length; i++) {
199
+ let memberMatch = memberMatchs[i];
200
+ let memberLine = memberMatch[1];
201
+ memberLines.push(`${memberLine}.TR()`);
202
+ }
203
+ convertedAssignLine = assignHead + memberLines.join(" + ") + ";";
204
+ }
205
+ else {
206
+ convertedAssignLine = assignLine;
207
+ }
186
208
  }
187
209
  let convertedAssignLine2 = convertedAssignLine.replaceAll(this.stringFormatPattern, `${trclassname}.Format`);
188
210
  snippets.push({
@@ -195,17 +217,18 @@ class CSCodeScanner {
195
217
  }
196
218
  return snippets;
197
219
  }
198
- static replaceStringsTR(stringMatch, stringLine, bodyLine) {
220
+ static replaceStringsTR(stringMatch, stringLine, bodyLine, trmethodname) {
199
221
  if (this.isNativeString(stringLine)) {
200
222
  return stringLine;
201
223
  }
224
+ let trmethodcall = `.${trmethodname}()`;
202
225
  let formattedStringLine = stringLine;
203
226
  let stringStartIndex = stringMatch.index;
204
227
  let stringEndIndex = stringStartIndex + stringLine.length;
205
228
  let prefix = bodyLine.substring(stringStartIndex - 2, stringStartIndex);
206
- let suffix = bodyLine.substring(stringEndIndex, stringEndIndex + ".TR()".length);
207
- if ((stringStartIndex == 0 || prefix == "+ ") && suffix != ".TR()") {
208
- formattedStringLine = formattedStringLine + ".TR()";
229
+ let suffix = bodyLine.substring(stringEndIndex, stringEndIndex + trmethodcall.length);
230
+ if ((stringStartIndex == 0 || prefix == "+ ") && suffix != trmethodcall) {
231
+ formattedStringLine = formattedStringLine + trmethodcall;
209
232
  }
210
233
  return formattedStringLine;
211
234
  }
@@ -47,7 +47,7 @@ class LiteralCollector {
47
47
  }
48
48
  let files = glob_1.glob.sync("**/*.cs", { cwd: folder });
49
49
  let testFullPath = "@";
50
- // let testFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/FGUI/ShopCommon/ShopCommonDialog.cs";
50
+ // let testFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/FGUI/RefineUI_FurnaceUpgradeDialog/Comp/ItemFurnaceRateComp.cs";
51
51
  for (const filePath of files) {
52
52
  let fullPath = folder + filePath;
53
53
  if (testFullPath != "@") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scancscode",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {
@@ -10,6 +10,9 @@ export class CSCodeScanner {
10
10
 
11
11
  // 正则表达式匹配 匹配每个字符串
12
12
  private static readonly stringPattern = /\$?"([^"]*)"/mg;
13
+ // 正则表达式匹配 匹配获取成员值的表达式
14
+ private static readonly getMemberValuePattern = /\s*(?:\+\s*)?([\w\.\u4e00-\u9fff\[\]]+)(\.TR\(\))?/mg;
15
+ private static readonly memberSplit = /^[\s\+;]/;
13
16
  // 正则表达式匹配插值表达式 {...}
14
17
  private static readonly interpolationPattern = /\{([^}]+?)(\:[a-zA-Z\d-\.\#(?:\\\\:)\u4e00-\u9fff]+)?\}/mg;
15
18
 
@@ -167,14 +170,14 @@ export class CSCodeScanner {
167
170
  // if ((stringStartIndex == 0 || prefix == "+ ") && suffix != ".TR()") {
168
171
  // formattedStringLine = formattedStringLine + ".TR()"
169
172
  // }
170
- formattedStringLine = this.replaceStringsTR(stringMatch, stringLine, bodyLine);
173
+ formattedStringLine = this.replaceStringsTR(stringMatch, stringLine, bodyLine, trmethodname);
171
174
  literals.push(stringContent);
172
175
  }
173
176
  convertedString = formattedStringLine;
174
177
  }
175
178
  } else {
176
179
  literals.push(stringContent);
177
- convertedString = this.replaceStringsTR(stringMatch, stringLine, bodyLine);
180
+ convertedString = this.replaceStringsTR(stringMatch, stringLine, bodyLine, trmethodname);
178
181
  }
179
182
 
180
183
  // 串联字符串列表
@@ -190,7 +193,25 @@ export class CSCodeScanner {
190
193
  convertedAssignLine = stringLines.join("");
191
194
  }
192
195
  } else {
193
- convertedAssignLine = assignLine;
196
+ const memberMatchs = [...bodyLine.matchAll(CSCodeScanner.getMemberValuePattern)];
197
+ if (memberMatchs.length == 1) {
198
+ let match1 = memberMatchs[0]
199
+ let c2 = bodyLine.substring(match1.index + match1[0].length)
200
+ if (c2 != '' && c2.match(CSCodeScanner.memberSplit) == null) {
201
+ memberMatchs.length = 0;
202
+ }
203
+ }
204
+ if (memberMatchs.length > 0) {
205
+ let memberLines: string[] = []
206
+ for (let i = 0; i < memberMatchs.length; i++) {
207
+ let memberMatch = memberMatchs[i];
208
+ let memberLine = memberMatch[1];
209
+ memberLines.push(`${memberLine}.TR()`);
210
+ }
211
+ convertedAssignLine = assignHead + memberLines.join(" + ") + ";";
212
+ } else {
213
+ convertedAssignLine = assignLine;
214
+ }
194
215
  }
195
216
 
196
217
  let convertedAssignLine2 = convertedAssignLine.replaceAll(this.stringFormatPattern, `${trclassname}.Format`);
@@ -207,18 +228,19 @@ export class CSCodeScanner {
207
228
  return snippets;
208
229
  }
209
230
 
210
- public static replaceStringsTR(stringMatch: RegExpExecArray, stringLine: string, bodyLine: string) {
231
+ public static replaceStringsTR(stringMatch: RegExpExecArray, stringLine: string, bodyLine: string, trmethodname: string): string {
211
232
  if (this.isNativeString(stringLine)) {
212
233
  return stringLine;
213
234
  }
214
235
 
236
+ let trmethodcall = `.${trmethodname}()`;
215
237
  let formattedStringLine = stringLine;
216
238
  let stringStartIndex = stringMatch.index;
217
239
  let stringEndIndex = stringStartIndex + stringLine.length;
218
240
  let prefix = bodyLine.substring(stringStartIndex - 2, stringStartIndex);
219
- let suffix = bodyLine.substring(stringEndIndex, stringEndIndex + ".TR()".length);
220
- if ((stringStartIndex == 0 || prefix == "+ ") && suffix != ".TR()") {
221
- formattedStringLine = formattedStringLine + ".TR()";
241
+ let suffix = bodyLine.substring(stringEndIndex, stringEndIndex + trmethodcall.length);
242
+ if ((stringStartIndex == 0 || prefix == "+ ") && suffix != trmethodcall) {
243
+ formattedStringLine = formattedStringLine + trmethodcall;
222
244
  }
223
245
  return formattedStringLine;
224
246
  }
@@ -15,7 +15,7 @@ export class LiteralCollector {
15
15
 
16
16
  let files = glob.sync("**/*.cs", { cwd: folder });
17
17
  let testFullPath = "@";
18
- // let testFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/FGUI/ShopCommon/ShopCommonDialog.cs";
18
+ // let testFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/FGUI/RefineUI_FurnaceUpgradeDialog/Comp/ItemFurnaceRateComp.cs";
19
19
  for (const filePath of files) {
20
20
  let fullPath = folder + filePath;
21
21
  if (testFullPath != "@") {