Repository: nagisc007/storybuilder

Issue:
Need to fix: kakko space bug
”」　”になる
===

**Description**
かぎかっこの後については考慮されていなかったようで、combineしてしまうとそこが空白が空いてしまう。


Discussion:

Patch:
diff --git a/builder/commons.py b/builder/commons.py
index e3b2870..39450a5 100644
--- a/builder/commons.py
+++ b/builder/commons.py
@@ -69,6 +69,16 @@ def dialogue_from_info(act: Action, lang: LangType) -> str:
     return "「{}」".format(infos_of(act).replace('/', '、')) if lang == LangType.JPN else ' "{}" '.format(infos_of(act).replace('/', ', '))
 
 
+def double_comma_chopped(target: str, lang: LangType) -> str:
+    assert_isstr(target)
+    assert_isclass(lang, LangType)
+
+    if lang is LangType.JPN:
+        return re.sub(r'([、。]){2}', r'\1', target)
+    else:
+        return re.sub(r'([,\.]){2}', r'\1', target)
+
+
 def extraend_chopped(target: str, lang: LangType) -> str:
     assert_isstr(target)
     assert_isclass(lang, LangType)
@@ -84,7 +94,7 @@ def extraspace_chopped(target: str, lang: LangType) -> str:
     assert_isclass(lang, LangType)
 
     if lang is LangType.JPN:
-        return re.sub(r'。[　、](.)', r'。\1', target)
+        return re.sub(r'([。」])[　、](.)', r'\1\2', target)
     else:
         return re.sub(r' +', r' ', target)
 
diff --git a/builder/tools.py b/builder/tools.py
index ec01600..289d08c 100644
--- a/builder/tools.py
+++ b/builder/tools.py
@@ -8,7 +8,8 @@ import re
 from .sbutils import assert_isclass, assert_isbool, assert_isint, assert_isstr
 from .action import Action, ActionGroup, TagAction
 from .commons import behavior_with_np_of, descriptions_of_if, dialogue_from_description_if, dialogue_from_info
-from .commons import extraspace_chopped, extraend_chopped, infos_of, object_names_of, sentence_from, subject_name_of
+from .commons import double_comma_chopped, extraspace_chopped, extraend_chopped
+from .commons import infos_of, object_names_of, sentence_from, subject_name_of
 from .enums import ActType, GroupType, TagType, LangType
 from .subject import _BaseSubject
 from .person import Person
@@ -285,6 +286,18 @@ def _desc_excepted_symbols(target: str) -> str:
 
     return re.sub(r'　|\s|\n|\r', '', target)
 
+
+def _extra_chopped(target: str, lang: LangType) -> str:
+    assert_isstr(target)
+    assert_isclass(lang, LangType)
+
+    return double_comma_chopped(
+            extraend_chopped(
+                extraspace_chopped(target, lang),
+                lang),
+            lang)
+
+
 def _flag_info_if(act: Action) -> str:
     assert_isclass(act, Action)
 
@@ -412,9 +425,9 @@ def _story_converted_as_description_in_group(group: ActionGroup, group_type: Gro
         else:
             val = _description_of_by_type(a, group.lang, group.group_type, level, pri_filter, is_debug)
             if val:
-                tmp.append(extraend_chopped(extraspace_chopped(val, group.lang), group.lang))
+                tmp.append(_extra_chopped(val, group.lang))
     if group_type is GroupType.COMBI:
-        return [extraend_chopped(extraspace_chopped("".join(tmp), group.lang), group.lang),]
+        return [_extra_chopped("".join(tmp), group.lang),]
     else:
         return tmp
 


Test patch:
diff --git a/tests/test_commons.py b/tests/test_commons.py
index d31cac1..7251069 100644
--- a/tests/test_commons.py
+++ b/tests/test_commons.py
@@ -128,6 +128,18 @@ class PublicMethodsTest(unittest.TestCase):
             with self.subTest(act=act, lng=lng, expected=expected):
                 self.assertEqual(commons.dialogue_from_info(act, lng), expected)
 
+    def test_double_comma_chopped(self):
+        data = [
+                ("　これを。。ただしく。。", LangType.JPN,
+                    "　これを。ただしく。"),
+                (" This is a pen.. the pen. ", LangType.ENG,
+                    " This is a pen. the pen. "),
+                ]
+
+        for v, lng, expected in data:
+            with self.subTest(v=v, lng=lng, expected=expected):
+                self.assertEqual(commons.double_comma_chopped(v, lng), expected)
+
     def test_extraspace_chopped(self):
         data = [
                 ("　これを。　ただしくする。", LangType.JPN,
@@ -136,6 +148,8 @@ class PublicMethodsTest(unittest.TestCase):
                     " This is a pen. the pen. "),
                 ("　これを。、ただしくして。", LangType.JPN,
                     "　これを。ただしくして。"),
+                ("「これを」　正しくする。", LangType.JPN,
+                    "「これを」正しくする。"),
                 ]
 
         for v, lng, expected in data: