MCPcopy
hub / github.com/sml2h3/ddddocr / validate_charset_range

Function validate_charset_range

ddddocr/utils/validators.py:140–171  ·  view source on GitHub ↗

验证字符集范围参数 Args: charset_range: 字符集范围参数 Returns: bool: 参数是否有效 Raises: DDDDOCRError: 当参数无效时

(charset_range: Union[int, str, List[str]])

Source from the content-addressed store, hash-verified

138
139
140def validate_charset_range(charset_range: Union[int, str, List[str]]) -> bool:
141 """
142 验证字符集范围参数
143
144 Args:
145 charset_range: 字符集范围参数
146
147 Returns:
148 bool: 参数是否有效
149
150 Raises:
151 DDDDOCRError: 当参数无效时
152 """
153 if charset_range is None:
154 return True
155
156 if isinstance(charset_range, int):
157 if charset_range < 0:
158 raise DDDDOCRError("字符集范围索引必须为非负整数")
159 elif isinstance(charset_range, str):
160 if len(charset_range) == 0:
161 raise DDDDOCRError("字符集范围字符串不能为空")
162 elif isinstance(charset_range, list):
163 if len(charset_range) == 0:
164 raise DDDDOCRError("字符集范围列表不能为空")
165 for char in charset_range:
166 if not isinstance(char, str):
167 raise DDDDOCRError("字符集范围列表中的元素必须为字符串")
168 else:
169 raise DDDDOCRError(f"不支持的字符集范围类型: {type(charset_range)}")
170
171 return True

Callers 1

set_rangesMethod · 0.85

Calls 1

DDDDOCRErrorClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…