Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fallenstardust
YGOMobile
Commits
04ddf61e
Commit
04ddf61e
authored
Aug 06, 2025
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加处理\\r\\n转义保存为\r\n
parent
1469d245
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
15 deletions
+30
-15
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck_square/DeckSquareFileUtil.java
...mb/ygomobile/ui/cards/deck_square/DeckSquareFileUtil.java
+30
-15
No files found.
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck_square/DeckSquareFileUtil.java
View file @
04ddf61e
...
@@ -143,7 +143,7 @@ public class DeckSquareFileUtil {
...
@@ -143,7 +143,7 @@ public class DeckSquareFileUtil {
}
}
/**
/**
* 处理单个YDK文件中的换行符,将\n、\\n、/n替换为实际换行(\r\n)
* 处理单个YDK文件中的换行符,将\n、\\n、/n
、\\r\\n
替换为实际换行(\r\n)
* 确保文本中的换行标记能真实换行显示
* 确保文本中的换行标记能真实换行显示
*/
*/
private
static
void
processYdkLineBreaks
(
File
ydkFile
)
{
private
static
void
processYdkLineBreaks
(
File
ydkFile
)
{
...
@@ -159,20 +159,7 @@ public class DeckSquareFileUtil {
...
@@ -159,20 +159,7 @@ public class DeckSquareFileUtil {
while
((
bytesRead
=
isr
.
read
(
buffer
))
!=
-
1
)
{
while
((
bytesRead
=
isr
.
read
(
buffer
))
!=
-
1
)
{
contentBuilder
.
append
(
buffer
,
0
,
bytesRead
);
contentBuilder
.
append
(
buffer
,
0
,
bytesRead
);
}
}
String
content
=
contentBuilder
.
toString
();
String
content
=
processYdkLineBreaks
(
contentBuilder
.
toString
());
// 先处理转义的\\n(文本中显示为"\n"的字符串)
content
=
content
.
replace
(
"\\n"
,
"\r\n"
);
// 处理错误的/n(斜杠+n)
content
=
content
.
replace
(
"/n"
,
"\r\n"
);
// 处理标准换行符\n(确保统一为Windows风格的\r\n)
// 先移除可能存在的重复\r,避免出现\r\r\n的情况
content
=
content
.
replace
(
"\r"
,
""
);
// 再将所有\n替换为\r\n
content
=
content
.
replace
(
"\n"
,
"\r\n"
);
// 去除末尾可能多余的空行
content
=
content
.
trim
()
+
"\r\n"
;
// 将处理后的内容写回文件
// 将处理后的内容写回文件
fos
=
new
FileOutputStream
(
ydkFile
);
fos
=
new
FileOutputStream
(
ydkFile
);
...
@@ -188,6 +175,33 @@ public class DeckSquareFileUtil {
...
@@ -188,6 +175,33 @@ public class DeckSquareFileUtil {
}
}
}
}
/**
* 处理文本中的换行符,将\n、\\n、/n、\\r\\n替换为实际换行(\r\n)
* 确保文本中的换行标记能真实换行显示
* @param content 需要处理的原始文本内容
* @return 处理后的文本内容
*/
private
static
String
processYdkLineBreaks
(
String
content
)
{
if
(
content
==
null
)
{
return
null
;
}
// 先处理转义的\\r\\n(文本中显示为"\r\n"的字符串)
content
=
content
.
replace
(
"\\r\\n"
,
"\r\n"
);
// 处理转义的\\n(文本中显示为"\n"的字符串)
content
=
content
.
replace
(
"\\n"
,
"\r\n"
);
// 处理错误的/n(斜杠+n)
content
=
content
.
replace
(
"/n"
,
"\r\n"
);
// 处理标准换行符\n(确保统一为Windows风格的\r\n)
// 先移除可能存在的重复\r,避免出现\r\r\n的情况
content
=
content
.
replace
(
"\r"
,
""
);
// 再将所有\n替换为\r\n
content
=
content
.
replace
(
"\n"
,
"\r\n"
);
// 去除末尾可能多余的空行,然后添加一个标准换行
return
content
.
trim
()
+
"\r\n"
;
}
//读取卡组目录下的所有ydk文件,解析ydk文件(包括从ydk文件内容中读取deckId),生成List<MyDeckItem>解析结果
//读取卡组目录下的所有ydk文件,解析ydk文件(包括从ydk文件内容中读取deckId),生成List<MyDeckItem>解析结果
public
static
List
<
MyDeckItem
>
getMyDeckItem
()
{
public
static
List
<
MyDeckItem
>
getMyDeckItem
()
{
List
<
MyDeckItem
>
result
=
new
ArrayList
<>();
List
<
MyDeckItem
>
result
=
new
ArrayList
<>();
...
@@ -292,6 +306,7 @@ public class DeckSquareFileUtil {
...
@@ -292,6 +306,7 @@ public class DeckSquareFileUtil {
// 创建文件输出流
// 创建文件输出流
fos
=
new
FileOutputStream
(
file
);
fos
=
new
FileOutputStream
(
file
);
// 写入内容
// 写入内容
content
=
processYdkLineBreaks
(
content
);
fos
.
write
(
content
.
getBytes
(
StandardCharsets
.
UTF_8
));
// 使用 UTF-8 编码
fos
.
write
(
content
.
getBytes
(
StandardCharsets
.
UTF_8
));
// 使用 UTF-8 编码
fos
.
flush
();
fos
.
flush
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment