summaryrefslogblamecommitdiff
path: root/src/strings/rstring.py
blob: 75fe2db2fd2c0e3ccda11d10ad7a8f5af3620620 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11


                                
                      
                          
                                   




                              













                                             
                       

                                    




                                                                 
 

                                    

                               
                                     

       













                                                                                                             
# used by other pretty-printers
rstring_disable_children = False

class RString(object):
    __slots__ = ('_value')
    name = 'tmwa::strings::RString'
    enabled = True

    def __init__(self, value):
        self._value = value

    def to_string(self):
        v = self._value
        e = v['maybe_end']
        if e:
            b = v['u']['begin']
            d = e - b
            return b.lazy_string(length=d)
        else:
            r = v['u']['owned'].dereference()
            b = r['body']
            b = b[0].address
            d = r['size']
            return b.lazy_string(length=d)

    def children(self):
        if rstring_disable_children:
            return
        v = self._value
        if v['maybe_end']:
            pass
        else:
            yield 'count', v['u']['owned'].dereference()['count']

    str256 = '0123456789abcdef' * 16

    test_extra = '''
    using tmwa::operator "" _s;
    #include "../strings/zstring.hpp"
    '''

    tests = [
            ('tmwa::RString(""_s)', '""'),
            ('tmwa::RString(tmwa::ZString(""_s))', '""'),
            ('tmwa::RString("Hello"_s)', '"Hello"'),
            ('tmwa::RString(tmwa::ZString("Hello"_s))', '"Hello" = {count = 0}'),
            ('tmwa::RString("' + str256[:-2] + '"_s)', '"' + str256[:-2] + '"'),
            ('tmwa::RString(tmwa::ZString("' + str256[:-2] + '"_s))', '"' + str256[:-2] + '" = {count = 0}'),
            ('tmwa::RString("' + str256[:-1] + '"_s)', '"' + str256[:-1] + '"'),
            ('tmwa::RString(tmwa::ZString("' + str256[:-1] + '"_s))', '"' + str256[:-1] + '" = {count = 0}'),
            ('tmwa::RString("' + str256 + '"_s)', '"' + str256 + '"'),
            ('tmwa::RString(tmwa::ZString("' + str256 + '"_s))', '"' + str256 + '" = {count = 0}'),
            ('tmwa::RString("' + str256 + 'x"_s)', '"' + str256 + 'x"'),
            ('tmwa::RString(tmwa::ZString("' + str256 + 'x"_s))', '"' + str256 + 'x" = {count = 0}'),
    ]