Răsfoiți Sursa

fix: 修正周次字符串解析逻辑,处理更多格式和空值情况

XingHeYuZhuan 3 săptămâni în urmă
părinte
comite
eb1921cde3
2 a modificat fișierele cu 24 adăugiri și 4 ștergeri
  1. 12 2
      resources/JSEI/jsei_01.js
  2. 12 2
      resources/XHKJZYXY/xhkjzyxy_01.js

+ 12 - 2
resources/JSEI/jsei_01.js

@@ -125,11 +125,16 @@ function mergeAndDistinctCourses(courses) {
 function parseWeeks(weekStr) {
     if (!weekStr) return [];
 
-    const cleaned = weekStr.replace(/周数[::]/g, '').replace(/周/g, '');
+    const cleaned = weekStr
+        .replace(/周数[::]/g, '')
+        .replace(/第/g, '')
+        .replace(/周/g, '')
+        .replace(/共\s*\d+\s*.*$/g, '');
+
     const segments = cleaned.split(/[,,、;;]/);
 
     const weeks = [];
-    const segRegex = /(\d+)(?:\s*[-~]\s*(\d+))?\s*([((][单双][))])?/g;
+    const segRegex = /(\d+)(?:\s*[-~]\s*(\d+))?\s*(?:[((]?\s*([单双])\s*周?\s*[))]?)?/g;
 
     for (const seg of segments) {
         const s = seg.trim();
@@ -138,6 +143,11 @@ function parseWeeks(weekStr) {
         segRegex.lastIndex = 0;
         let m;
         while ((m = segRegex.exec(s)) !== null) {
+            if (m[0] === '') {
+                segRegex.lastIndex++;
+                continue;
+            }
+
             const start = parseInt(m[1], 10);
             const end = m[2] ? parseInt(m[2], 10) : start;
             const flagStr = m[3] || '';

+ 12 - 2
resources/XHKJZYXY/xhkjzyxy_01.js

@@ -110,11 +110,16 @@ function mergeAndDistinctCourses(courses) {
 function parseWeeks(weekStr) {
     if (!weekStr) return [];
 
-    const cleaned = weekStr.replace(/周数[::]/g, '').replace(/周/g, '');
+    const cleaned = weekStr
+        .replace(/周数[::]/g, '')
+        .replace(/第/g, '')
+        .replace(/周/g, '')
+        .replace(/共\s*\d+\s*.*$/g, '');
+
     const segments = cleaned.split(/[,,、;;]/);
 
     const weeks = [];
-    const segRegex = /(\d+)(?:\s*[-~]\s*(\d+))?\s*([((][单双][))])?/g;
+    const segRegex = /(\d+)(?:\s*[-~]\s*(\d+))?\s*(?:[((]?\s*([单双])\s*周?\s*[))]?)?/g;
 
     for (const seg of segments) {
         const s = seg.trim();
@@ -123,6 +128,11 @@ function parseWeeks(weekStr) {
         segRegex.lastIndex = 0;
         let m;
         while ((m = segRegex.exec(s)) !== null) {
+            if (m[0] === '') {
+                segRegex.lastIndex++;
+                continue;
+            }
+
             const start = parseInt(m[1], 10);
             const end = m[2] ? parseInt(m[2], 10) : start;
             const flagStr = m[3] || '';