fix: maidata部分字段开头如果有空白字符时,会造成一些解析和处理过程(如add1Bar函数)出现错误。#47
fix: maidata部分字段开头如果有空白字符时,会造成一些解析和处理过程(如add1Bar函数)出现错误。#47clansty merged 1 commit intoMuNET-OSS:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在增强MaiChartManager处理maidata的健壮性。通过在数据导入阶段对特定关键字段进行空白字符修剪,解决了因数据源中意外的空白字符导致后续解析逻辑(特别是正则表达式匹配)失败的问题,从而提升了谱面数据处理的准确性和稳定性。 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
审阅者指南(在小型 PR 上折叠)审阅者指南在导入过程中,通过去除前后空白字符来规范化某些 maidata 字段,这样即使字段以换行或空格开头,下游解析(例如 add1Bar 的正则标签匹配)也能正确工作。 带裁剪字段的 maidata 导入与下游解析时序图sequenceDiagram
participant Caller
participant MaidataImportService
participant RegexTagParser
Caller->>MaidataImportService: ImportMaidata(rawMaidataText)
MaidataImportService->>MaidataImportService: Parse keyValuePairs from raw text
loop For each keyValuePair
MaidataImportService->>MaidataImportService: maiData[key] = value
alt Key is inote*, lv*, first*, wholebpm*
MaidataImportService->>MaidataImportService: maiData[key] = maiData[key].Trim()
else Other keys
MaidataImportService->>MaidataImportService: Store value without trimming
end
end
MaidataImportService-->>Caller: ImportChartResult with normalized maiData
Caller->>MaidataImportService: add1Bar(maiData, chartIndex)
MaidataImportService->>RegexTagParser: Match tags from maiData[inote_key]
RegexTagParser-->>MaidataImportService: Successful tag matches (no leading whitespace)
MaidataImportService-->>Caller: Updated chart with added bar
MaidataImportService 导入与规范化逻辑的更新类图classDiagram
class MaidataImportService {
+ImportChartResult ImportMaidata(string fileName, string rawMaidataText)
-Dictionary~string,string~ ParseKeyValuePairs(string rawMaidataText)
-void add1Bar(Dictionary~string,string~ maiData, int chartIndex)
}
class ImportChartResult {
+bool Success
+string Message
+Dictionary~int,AllChartsEntry~ AllCharts
}
class AllChartsEntry {
+int ChartIndex
+string InoteKey
+string LevelKey
+string FirstKey
+string WholeBpmKey
}
MaidataImportService --> ImportChartResult : returns
ImportChartResult "1" --> "*" AllChartsEntry : contains
note for MaidataImportService "ImportMaidata now trims values for keys starting with inote, lv, first and wholebpm before storing them in maiData"
文件级更改
技巧与命令与 Sourcery 交互
自定义你的体验访问你的控制面板以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideNormalizes certain maidata fields by trimming leading/trailing whitespace during import so that downstream parsing (e.g., add1Bar’s regex tag matching) works correctly even when fields start with line breaks or spaces. Sequence diagram for maidata import and downstream parsing with trimmed fieldssequenceDiagram
participant Caller
participant MaidataImportService
participant RegexTagParser
Caller->>MaidataImportService: ImportMaidata(rawMaidataText)
MaidataImportService->>MaidataImportService: Parse keyValuePairs from raw text
loop For each keyValuePair
MaidataImportService->>MaidataImportService: maiData[key] = value
alt Key is inote*, lv*, first*, wholebpm*
MaidataImportService->>MaidataImportService: maiData[key] = maiData[key].Trim()
else Other keys
MaidataImportService->>MaidataImportService: Store value without trimming
end
end
MaidataImportService-->>Caller: ImportChartResult with normalized maiData
Caller->>MaidataImportService: add1Bar(maiData, chartIndex)
MaidataImportService->>RegexTagParser: Match tags from maiData[inote_key]
RegexTagParser-->>MaidataImportService: Successful tag matches (no leading whitespace)
MaidataImportService-->>Caller: Updated chart with added bar
Updated class diagram for MaidataImportService import and normalization logicclassDiagram
class MaidataImportService {
+ImportChartResult ImportMaidata(string fileName, string rawMaidataText)
-Dictionary~string,string~ ParseKeyValuePairs(string rawMaidataText)
-void add1Bar(Dictionary~string,string~ maiData, int chartIndex)
}
class ImportChartResult {
+bool Success
+string Message
+Dictionary~int,AllChartsEntry~ AllCharts
}
class AllChartsEntry {
+int ChartIndex
+string InoteKey
+string LevelKey
+string FirstKey
+string WholeBpmKey
}
MaidataImportService --> ImportChartResult : returns
ImportChartResult "1" --> "*" AllChartsEntry : contains
note for MaidataImportService "ImportMaidata now trims values for keys starting with inote, lv, first and wholebpm before storing them in maiData"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我在这里给出了一些高层次的反馈:
- 当前的裁剪(trim)逻辑被重复执行了:先通过
maiData[key] = value;赋值,然后又进行第二次赋值;可以考虑在插入字典之前先对值进行 trim,或者使用一个局部变量来避免重复的查找和写入。 - 在内联条件中对键前缀(
inote,lv,first,wholebpm)进行硬编码,使这一规则有些不够直观,也更难维护;可以考虑将这组前缀,或者ShouldTrimKey(string key)这样的谓词提取到单独的方法或配置中,这样会更清晰,也更便于扩展。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- The trimming logic is currently duplicated via `maiData[key] = value;` followed by a second assignment; consider trimming the value before inserting into the dictionary or using a local variable to avoid redundant lookups and writes.
- Hardcoding the key prefixes (`inote`, `lv`, `first`, `wholebpm`) in an inline conditional makes the rule a bit opaque and harder to maintain; consider extracting the prefix set or the `ShouldTrimKey(string key)` predicate into a separate method or config so it’s clearer and easier to extend.帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English
Hey - I've left some high level feedback:
- The trimming logic is currently duplicated via
maiData[key] = value;followed by a second assignment; consider trimming the value before inserting into the dictionary or using a local variable to avoid redundant lookups and writes. - Hardcoding the key prefixes (
inote,lv,first,wholebpm) in an inline conditional makes the rule a bit opaque and harder to maintain; consider extracting the prefix set or theShouldTrimKey(string key)predicate into a separate method or config so it’s clearer and easier to extend.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The trimming logic is currently duplicated via `maiData[key] = value;` followed by a second assignment; consider trimming the value before inserting into the dictionary or using a local variable to avoid redundant lookups and writes.
- Hardcoding the key prefixes (`inote`, `lv`, `first`, `wholebpm`) in an inline conditional makes the rule a bit opaque and harder to maintain; consider extracting the prefix set or the `ShouldTrimKey(string key)` predicate into a separate method or config so it’s clearer and easier to extend.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| maiData[key] = value; | ||
| if (key.StartsWith("inote") || key.StartsWith("lv") || key.StartsWith("first") || | ||
| key.StartsWith("wholebpm")) maiData[key] = maiData[key].Trim(); |
There was a problem hiding this comment.
这里的实现虽然能正常工作,但会存在对字典的重复写入问题。当 if 条件满足时,会先执行 maiData[key] = value;,然后再执行 maiData[key] = maiData[key].Trim();,对同一个键写入了两次。
为了避免这种情况,我们可以重构一下,根据条件只写入一次。这样代码会更高效和清晰。
if (key.StartsWith("inote") || key.StartsWith("lv") || key.StartsWith("first") ||
key.StartsWith("wholebpm"))
{
maiData[key] = value.Trim();
}
else
{
maiData[key] = value;
}
出问题谱面节选:
这时,在
MaiChartManager/MaiChartManager/Services/MaidataImportService.cs
Lines 272 to 277 in 80ed4ba
所解析出的maidata会形如
[inote_5] = "\r\n(180){8}5/6h[8:11],4",开头有一个\r\n这就导致
add1Bar里所调用的MaiChartManager/MaiChartManager/Services/MaidataImportService.cs
Lines 50 to 51 in 80ed4ba
这里的正则表达式无法匹配到tag了,因为它限定“要从谱面文本开头开始匹配”,但开头是个
\r\n。从根本性解决问题,最好是把所有谱面
i_note的开头结尾都trim掉,这样是比较保险的。至于为什么只triminotelvfirst等字段,不trimtitleartist之类的,想想如月车站(歌名为日文全角空格\u3000)就知道了。Summary by Sourcery
错误修复:
maidata中inote、lv、first和wholebpm键值周围的空白字符,对这些值进行规范化处理,从而确保基于正则表达式的标签解析能够正常工作。Original summary in English
Summary by Sourcery
Bug Fixes: