当前位置: 首页>>代码示例>>Python>>正文


Python StringBuilder.append_slice方法代码示例

本文整理汇总了Python中pypy.rlib.rstring.StringBuilder.append_slice方法的典型用法代码示例。如果您正苦于以下问题:Python StringBuilder.append_slice方法的具体用法?Python StringBuilder.append_slice怎么用?Python StringBuilder.append_slice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pypy.rlib.rstring.StringBuilder的用法示例。


在下文中一共展示了StringBuilder.append_slice方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fn

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_slice [as 别名]
 def fn(_):
     s = StringBuilder()
     s.append("a")
     s.append("abc")
     s.append_slice("abc", 1, 2)
     s.append_multiple_char('d', 4)
     return s.build()
开发者ID:pombredanne,项目名称:pypy,代码行数:9,代码来源:test_newgc.py

示例2: test_string_builder

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_slice [as 别名]
def test_string_builder():
    s = StringBuilder()
    s.append("a")
    s.append("abc")
    s.append("a")
    s.append_slice("abc", 1, 2)
    s.append_multiple_char('d', 4)
    assert s.build() == "aabcabdddd"
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:test_rstring.py

示例3: str_zfill__String_ANY

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_slice [as 别名]
def str_zfill__String_ANY(space, w_self, w_width):
    input = w_self._value
    width = space.int_w(w_width)

    num_zeros = width - len(input)
    if num_zeros <= 0:
        # cannot return w_self, in case it is a subclass of str
        return space.wrap(input)

    builder = StringBuilder(width)
    if len(input) > 0 and (input[0] == '+' or input[0] == '-'):
        builder.append(input[0])
        start = 1
    else:
        start = 0

    builder.append_multiple_char('0', num_zeros)
    builder.append_slice(input, start, len(input))
    return space.wrap(builder.build())
开发者ID:craigkerstiens,项目名称:pypy,代码行数:21,代码来源:stringobject.py

示例4: descr_repr

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_slice [as 别名]
 def descr_repr(self, space):
     res = StringBuilder()
     res.append("array(")
     concrete = self.get_concrete()
     dtype = concrete.find_dtype()
     if not concrete.find_size():
         res.append('[]')
         if len(self.shape) > 1:
             # An empty slice reports its shape
             res.append(", shape=(")
             self_shape = str(self.shape)
             res.append_slice(str(self_shape), 1, len(self_shape) - 1)
             res.append(')')
     else:
         concrete.to_str(space, 1, res, indent='       ')
     if (dtype is not space.fromcache(interp_dtype.W_Float64Dtype) and
         dtype is not space.fromcache(interp_dtype.W_Int64Dtype)) or \
         not self.find_size():
         res.append(", dtype=" + dtype.name)
     res.append(")")
     return space.wrap(res.build())
开发者ID:craigkerstiens,项目名称:pypy,代码行数:23,代码来源:interp_numarray.py

示例5: repr__String

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_slice [as 别名]
def repr__String(space, w_str):
    s = w_str._value

    buf = StringBuilder(50)

    quote = "'"
    if quote in s and '"' not in s:
        quote = '"'

    buf.append(quote)
    startslice = 0

    for i in range(len(s)):
        c = s[i]
        use_bs_char = False  # character quoted by backspace

        if c == "\\" or c == quote:
            bs_char = c
            use_bs_char = True
        elif c == "\t":
            bs_char = "t"
            use_bs_char = True
        elif c == "\r":
            bs_char = "r"
            use_bs_char = True
        elif c == "\n":
            bs_char = "n"
            use_bs_char = True
        elif not "\x20" <= c < "\x7f":
            n = ord(c)
            if i != startslice:
                buf.append_slice(s, startslice, i)
            startslice = i + 1
            buf.append("\\x")
            buf.append("0123456789abcdef"[n >> 4])
            buf.append("0123456789abcdef"[n & 0xF])

        if use_bs_char:
            if i != startslice:
                buf.append_slice(s, startslice, i)
            startslice = i + 1
            buf.append("\\")
            buf.append(bs_char)

    if len(s) != startslice:
        buf.append_slice(s, startslice, len(s))

    buf.append(quote)

    return space.wrap(buf.build())
开发者ID:alkorzt,项目名称:pypy,代码行数:52,代码来源:stringobject.py

示例6: string_escape_encode

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_slice [as 别名]
def string_escape_encode(s, quote):

    buf = StringBuilder(len(s) + 2)

    buf.append(quote)
    startslice = 0

    for i in range(len(s)):
        c = s[i]
        use_bs_char = False # character quoted by backspace

        if c == '\\' or c == quote:
            bs_char = c
            use_bs_char = True
        elif c == '\t':
            bs_char = 't'
            use_bs_char = True
        elif c == '\r':
            bs_char = 'r'
            use_bs_char = True
        elif c == '\n':
            bs_char = 'n'
            use_bs_char = True
        elif not '\x20' <= c < '\x7f':
            n = ord(c)
            if i != startslice:
                buf.append_slice(s, startslice, i)
            startslice = i + 1
            buf.append('\\x')
            buf.append("0123456789abcdef"[n>>4])
            buf.append("0123456789abcdef"[n&0xF])

        if use_bs_char:
            if i != startslice:
                buf.append_slice(s, startslice, i)
            startslice = i + 1
            buf.append('\\')
            buf.append(bs_char)

    if len(s) != startslice:
        buf.append_slice(s, startslice, len(s))

    buf.append(quote)

    return buf.build()
开发者ID:craigkerstiens,项目名称:pypy,代码行数:47,代码来源:stringobject.py

示例7: PyString_DecodeEscape

# 需要导入模块: from pypy.rlib.rstring import StringBuilder [as 别名]
# 或者: from pypy.rlib.rstring.StringBuilder import append_slice [as 别名]
def PyString_DecodeEscape(space, s, recode_encoding):
    """
    Unescape a backslash-escaped string. If recode_encoding is non-zero,
    the string is UTF-8 encoded and should be re-encoded in the
    specified encoding.
    """
    builder = StringBuilder(len(s))
    ps = 0
    end = len(s)
    while 1:
        ps2 = ps
        while ps < end and s[ps] != '\\':
            if recode_encoding and ord(s[ps]) & 0x80:
                w, ps = decode_utf8(space, s, ps, end, recode_encoding)
                builder.append(w)
                ps2 = ps
            else:
                ps += 1
        if ps > ps2:
            builder.append_slice(s, ps2, ps)
        if ps == end:
            break

        ps += 1
        if ps == end:
            raise_app_valueerror(space, 'Trailing \\ in string')
        prevps = ps
        ch = s[ps]
        ps += 1
        # XXX This assumes ASCII!
        if ch == '\n':
            pass
        elif ch == '\\':
            builder.append('\\')
        elif ch == "'":
            builder.append("'")
        elif ch == '"':
            builder.append('"')
        elif ch == 'b':
            builder.append("\010")
        elif ch == 'f':
            builder.append('\014') # FF
        elif ch == 't':
            builder.append('\t')
        elif ch == 'n':
            builder.append('\n')
        elif ch == 'r':
            builder.append('\r')
        elif ch == 'v':
            builder.append('\013') # VT
        elif ch == 'a':
            builder.append('\007') # BEL, not classic C
        elif ch in '01234567':
            # Look for up to two more octal digits
            span = ps
            span += (span < end) and (s[span] in '01234567')
            span += (span < end) and (s[span] in '01234567')
            octal = s[prevps : span]
            # emulate a strange wrap-around behavior of CPython:
            # \400 is the same as \000 because 0400 == 256
            num = int(octal, 8) & 0xFF
            builder.append(chr(num))
            ps = span
        elif ch == 'x':
            if ps+2 <= end and isxdigit(s[ps]) and isxdigit(s[ps + 1]):
                hexa = s[ps : ps + 2]
                num = int(hexa, 16)
                builder.append(chr(num))
                ps += 2
            else:
                raise_app_valueerror(space, 'invalid \\x escape')
            # ignored replace and ignore for now

        else:
            # this was not an escape, so the backslash
            # has to be added, and we start over in
            # non-escape mode.
            builder.append('\\')
            ps -= 1
            assert ps >= 0
            continue
            # an arbitry number of unescaped UTF-8 bytes may follow.

    buf = builder.build()
    return buf
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:87,代码来源:parsestring.py


注:本文中的pypy.rlib.rstring.StringBuilder.append_slice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。