prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  LineStrParser: separator behaviour
  I've a question regarding this snippet of code:
  https://github.com/open-mmlab/mmocr/blob/01d8d63be945882fb2d9eaca5e1c1b39cb45f274/mmocr/datasets/utils/parser.py#L33-L36
  
  Is there a particular reason to use these 4 lines of code instead of simply `line_str = line_str.split(self.separator)`?
  
  I'm asking this because for my own use case I have:
  - a TSV file with `filename` and `text` as keys for text recognition task
  - some blank spaces in `filename` e.g. `my cropped image.png`
   
  Hence, LineStrParser is configured as follows:
  ```python
  parser=dict(
              type='LineStrParser',
              keys=['filename', 'text'],
              keys_idx=[0, 1],
              separator='\t'))
  ```
  but with the 4-lines code snippet, the line parsing fails. Instead, with simply `line_str = line_str.split(self.separator)` everything works well.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `mmocr/datasets/utils/parser.py`
  Content:
  ```
  1 import json
  2 
  3 from mmocr.datasets.builder import PARSERS
  4 
  5 
  6 @PARSERS.register_module()
  7 class LineStrParser:
  8     """Parse string of one line in annotation file to dict format.
  9 
  10     Args:
  11         keys (list[str]): Keys in result dict.
  12         keys_idx (list[int]): Value index in sub-string list
  13             for each key above.
  14         separator (str): Separator to separate string to list of sub-string.
  15     """
  16 
  17     def __init__(self,
  18                  keys=['filename', 'text'],
  19                  keys_idx=[0, 1],
  20                  separator=' '):
  21         assert isinstance(keys, list)
  22         assert isinstance(keys_idx, list)
  23         assert isinstance(separator, str)
  24         assert len(keys) > 0
  25         assert len(keys) == len(keys_idx)
  26         self.keys = keys
  27         self.keys_idx = keys_idx
  28         self.separator = separator
  29 
  30     def get_item(self, data_ret, index):
  31         map_index = index % len(data_ret)
  32         line_str = data_ret[map_index]
  33         for split_key in self.separator:
  34             if split_key != ' ':
  35                 line_str = line_str.replace(split_key, ' ')
  36         line_str = line_str.split()
  37         if len(line_str) <= max(self.keys_idx):
  38             raise Exception(
  39                 f'key index: {max(self.keys_idx)} out of range: {line_str}')
  40 
  41         line_info = {}
  42         for i, key in enumerate(self.keys):
  43             line_info[key] = line_str[self.keys_idx[i]]
  44         return line_info
  45 
  46 
  47 @PARSERS.register_module()
  48 class LineJsonParser:
  49     """Parse json-string of one line in annotation file to dict format.
  50 
  51     Args:
  52         keys (list[str]): Keys in both json-string and result dict.
  53     """
  54 
  55     def __init__(self, keys=[], **kwargs):
  56         assert isinstance(keys, list)
  57         assert len(keys) > 0
  58         self.keys = keys
  59 
  60     def get_item(self, data_ret, index):
  61         map_index = index % len(data_ret)
  62         line_json_obj = json.loads(data_ret[map_index])
  63         line_info = {}
  64         for key in self.keys:
  65             if key not in line_json_obj:
  66                 raise Exception(f'key {key} not in line json {line_json_obj}')
  67             line_info[key] = line_json_obj[key]
  68 
  69         return line_info
  70
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/mmocr/datasets/utils/parser.py b/mmocr/datasets/utils/parser.py
  --- a/mmocr/datasets/utils/parser.py
  +++ b/mmocr/datasets/utils/parser.py
  @@ -30,10 +30,7 @@
       def get_item(self, data_ret, index):
           map_index = index % len(data_ret)
           line_str = data_ret[map_index]
  -        for split_key in self.separator:
  -            if split_key != ' ':
  -                line_str = line_str.replace(split_key, ' ')
  -        line_str = line_str.split()
  +        line_str = line_str.split(self.separator)
           if len(line_str) <= max(self.keys_idx):
               raise Exception(
                   f'key index: {max(self.keys_idx)} out of range: {line_str}')
  
verification_info: {"golden_diff": "diff --git a/mmocr/datasets/utils/parser.py b/mmocr/datasets/utils/parser.py\n--- a/mmocr/datasets/utils/parser.py\n+++ b/mmocr/datasets/utils/parser.py\n@@ -30,10 +30,7 @@\n     def get_item(self, data_ret, index):\n         map_index = index % len(data_ret)\n         line_str = data_ret[map_index]\n-        for split_key in self.separator:\n-            if split_key != ' ':\n-                line_str = line_str.replace(split_key, ' ')\n-        line_str = line_str.split()\n+        line_str = line_str.split(self.separator)\n         if len(line_str) <= max(self.keys_idx):\n             raise Exception(\n                 f'key index: {max(self.keys_idx)} out of range: {line_str}')\n", "issue": "LineStrParser: separator behaviour\nI've a question regarding this snippet of code:\r\nhttps://github.com/open-mmlab/mmocr/blob/01d8d63be945882fb2d9eaca5e1c1b39cb45f274/mmocr/datasets/utils/parser.py#L33-L36\r\n\r\nIs there a particular reason to use these 4 lines of code instead of simply `line_str = line_str.split(self.separator)`?\r\n\r\nI'm asking this because for my own use case I have:\r\n- a TSV file with `filename` and `text` as keys for text recognition task\r\n- some blank spaces in `filename` e.g. `my cropped image.png`\r\n \r\nHence, LineStrParser is configured as follows:\r\n```python\r\nparser=dict(\r\n            type='LineStrParser',\r\n            keys=['filename', 'text'],\r\n            keys_idx=[0, 1],\r\n            separator='\\t'))\r\n```\r\nbut with the 4-lines code snippet, the line parsing fails. Instead, with simply `line_str = line_str.split(self.separator)` everything works well.\n", "before_files": [{"content": "import json\n\nfrom mmocr.datasets.builder import PARSERS\n\n\n@PARSERS.register_module()\nclass LineStrParser:\n    \"\"\"Parse string of one line in annotation file to dict format.\n\n    Args:\n        keys (list[str]): Keys in result dict.\n        keys_idx (list[int]): Value index in sub-string list\n            for each key above.\n        separator (str): Separator to separate string to list of sub-string.\n    \"\"\"\n\n    def __init__(self,\n                 keys=['filename', 'text'],\n                 keys_idx=[0, 1],\n                 separator=' '):\n        assert isinstance(keys, list)\n        assert isinstance(keys_idx, list)\n        assert isinstance(separator, str)\n        assert len(keys) > 0\n        assert len(keys) == len(keys_idx)\n        self.keys = keys\n        self.keys_idx = keys_idx\n        self.separator = separator\n\n    def get_item(self, data_ret, index):\n        map_index = index % len(data_ret)\n        line_str = data_ret[map_index]\n        for split_key in self.separator:\n            if split_key != ' ':\n                line_str = line_str.replace(split_key, ' ')\n        line_str = line_str.split()\n        if len(line_str) <= max(self.keys_idx):\n            raise Exception(\n                f'key index: {max(self.keys_idx)} out of range: {line_str}')\n\n        line_info = {}\n        for i, key in enumerate(self.keys):\n            line_info[key] = line_str[self.keys_idx[i]]\n        return line_info\n\n\n@PARSERS.register_module()\nclass LineJsonParser:\n    \"\"\"Parse json-string of one line in annotation file to dict format.\n\n    Args:\n        keys (list[str]): Keys in both json-string and result dict.\n    \"\"\"\n\n    def __init__(self, keys=[], **kwargs):\n        assert isinstance(keys, list)\n        assert len(keys) > 0\n        self.keys = keys\n\n    def get_item(self, data_ret, index):\n        map_index = index % len(data_ret)\n        line_json_obj = json.loads(data_ret[map_index])\n        line_info = {}\n        for key in self.keys:\n            if key not in line_json_obj:\n                raise Exception(f'key {key} not in line json {line_json_obj}')\n            line_info[key] = line_json_obj[key]\n\n        return line_info\n", "path": "mmocr/datasets/utils/parser.py"}], "after_files": [{"content": "import json\n\nfrom mmocr.datasets.builder import PARSERS\n\n\n@PARSERS.register_module()\nclass LineStrParser:\n    \"\"\"Parse string of one line in annotation file to dict format.\n\n    Args:\n        keys (list[str]): Keys in result dict.\n        keys_idx (list[int]): Value index in sub-string list\n            for each key above.\n        separator (str): Separator to separate string to list of sub-string.\n    \"\"\"\n\n    def __init__(self,\n                 keys=['filename', 'text'],\n                 keys_idx=[0, 1],\n                 separator=' '):\n        assert isinstance(keys, list)\n        assert isinstance(keys_idx, list)\n        assert isinstance(separator, str)\n        assert len(keys) > 0\n        assert len(keys) == len(keys_idx)\n        self.keys = keys\n        self.keys_idx = keys_idx\n        self.separator = separator\n\n    def get_item(self, data_ret, index):\n        map_index = index % len(data_ret)\n        line_str = data_ret[map_index]\n        line_str = line_str.split(self.separator)\n        if len(line_str) <= max(self.keys_idx):\n            raise Exception(\n                f'key index: {max(self.keys_idx)} out of range: {line_str}')\n\n        line_info = {}\n        for i, key in enumerate(self.keys):\n            line_info[key] = line_str[self.keys_idx[i]]\n        return line_info\n\n\n@PARSERS.register_module()\nclass LineJsonParser:\n    \"\"\"Parse json-string of one line in annotation file to dict format.\n\n    Args:\n        keys (list[str]): Keys in both json-string and result dict.\n    \"\"\"\n\n    def __init__(self, keys=[], **kwargs):\n        assert isinstance(keys, list)\n        assert len(keys) > 0\n        self.keys = keys\n\n    def get_item(self, data_ret, index):\n        map_index = index % len(data_ret)\n        line_json_obj = json.loads(data_ret[map_index])\n        line_info = {}\n        for key in self.keys:\n            if key not in line_json_obj:\n                raise Exception(f'key {key} not in line json {line_json_obj}')\n            line_info[key] = line_json_obj[key]\n\n        return line_info\n", "path": "mmocr/datasets/utils/parser.py"}]}