my_stringutils.py 1.25 KB
Newer Older
qunfeng qiu's avatar
qunfeng qiu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@Version: 1.0
@Python Version:3.6.6
@Author: ludq1
@Email: ludq1@chinaunicom.cn
@date: 2023/04/07 11:40:00
@Description:
"""

from .my_utils import MyUtils


class MyStringUtils:
    """
    字符串处理便捷函数
    """

    EMPTY = MyUtils.EMPTY

    @classmethod
    def to_str(cls, a_obj, trim: bool = False) -> str:
        r"""
        将对象转换为字符串, 当对象为None或对其调用str()函数返回为None时,返回 EMPTY

        Args:
            a_obj:
            trim:

        Returns:

        """
        return MyUtils.to_str(a_obj, trim=trim)

    @classmethod
    def is_empty(cls, a_str: str, trim: bool = False) -> bool:
        r"""
        检查字符串是否是空字符串, None和''都是true,其他为false

        Args:
            a_str:
            trim:

        Returns:

        """
        return MyUtils.is_empty(a_str, trim=trim)

    @classmethod
    def equals(cls, str1: str, str2: str) -> bool:
        r"""
        检查两个字符串是否相同,
        None 和 None 相同

        Args:
            str1:
            str2:

        Returns:

        """

        return MyUtils.equals(str1, str2)