コード例 #1
0
    def format_value(self, value):
        if isinstance(value, list):
            result = []

            for subvalue in value:
                result.append(self.format_value(subvalue))

            return '{0}'.format(','.join(result))

        type_ = self.get_type()

        if type_ == 'float':
            return common.format_float(value)

        if type_ == 'bool':
            return str(bool(value)).lower()

        if type_ == 'char':
            return '{0}'.format(value)  # FIXME: how to escape a single quote?

        if type_ == 'string':
            return '"{0}"'.format(
                value)  # FIXME: how to escape a double quote?

        return str(value)
コード例 #2
0
        def helper(value):
            if type_ == 'float':
                return common.format_float(value)
            elif type_ == 'bool':
                return str(bool(value))
            elif type_ == 'char':
                return 'ToCharacterCode["{0}"][[1]]'.format(
                    value.replace('"', '\\"'))
            elif type_ == 'string':
                return '"{0}"'.format(value.replace('"', '\\"'))
            elif ':bitmask:' in type_:
                bits = []

                for i in range(64):
                    if (value & (1 << i)) != 0:
                        bits = ['1'] + bits
                    else:
                        bits = ['0'] + bits

                length = int(type_.split(':')[2])

                return 'FromDigits[{{{0}}},2]'.format(','.join(bits[-length:]))
            elif type_.endswith(':constant'):
                return self.get_value_constant(value).get_mathematica_source()
            else:
                return str(value)
コード例 #3
0
        def helper(value):
            if type_ == 'float':
                return common.format_float(value) + 'f'
            elif type_ == 'bool':
                return str(bool(value)).lower()
            elif type_ == 'char':
                return "'{0}'".format(value.replace("'", "\\'"))
            elif type_ == 'string':
                return '"{0}"'.format(value.replace('"', '\\"'))
            elif ':bitmask:' in type_:
                value = common.make_c_like_bitmask(value)
                cast = java_common.get_java_type(
                    type_.split(':')[0],
                    1,
                    legacy=self.get_device().has_java_legacy_types())

                if cast in ['byte', 'short']:
                    return '({0})({1})'.format(cast, value)
                else:
                    return value
            elif type_.endswith(':constant'):
                return self.get_value_constant(value).get_java_source()
            else:
                cast = java_common.get_java_type(
                    type_, 1, legacy=self.get_device().has_java_legacy_types())

                if cast in ['byte', 'short']:
                    cast = '({0})'.format(cast)
                else:
                    cast = ''

                return cast + str(value)
コード例 #4
0
    def format_value(self, value):
        if isinstance(value, list):
            result = []

            for subvalue in value:
                result.append(self.format_value(subvalue))

            return '({0})'.format(', '.join(result))

        type_ = self.get_type()

        if type_ == 'float':
            return common.format_float(value)

        if type_ == 'bool':
            return str(bool(value))

        if type_ == 'char':
            return 'ToCharacterCode["{0}"][[0]]'.format(
                value.replace('"', '\\"'))

        if type_ == 'string':
            return '"{0}"'.format(value.replace('"', '\\"'))

        return str(value)
コード例 #5
0
 def helper(value):
     if type_ == 'float':
         return common.format_float(value)
     elif type_ == 'bool':
         return str(bool(value))
     elif type_ in ['char', 'string']:
         return '"{0}"'.format(value.replace('"', '\\"'))
     elif ':bitmask:' in type_:
         return common.make_c_like_bitmask(value)
     elif type_.endswith(':constant'):
         return self.get_value_constant(value).get_python_source()
     else:
         return str(value)
コード例 #6
0
 def helper(value):
     if type_ == 'float':
         return common.format_float(value)
     elif type_ == 'bool':
         return str(bool(value)).lower()
     elif type_ in ['char', 'string']:
         return "'{0}'".format(value.replace("'", "\\'"))
     elif ':bitmask:' in type_:
         return common.make_c_like_bitmask(value)
     elif type_.endswith(':constant'):
         return self.get_value_constant(value).get_javascript_source()
     else:
         return str(value)
コード例 #7
0
 def helper(value):
     if type_ == 'float':
         return common.format_float(value)
     elif type_ == 'bool':
         return str(bool(value)).lower()
     elif type_ in  ['char', 'string']:
         return global_quote + value.replace(global_quote, '\\' + global_quote) + global_quote
     elif ':bitmask:' in type_:
         return common.make_c_like_bitmask(value, shift='bitshift({0}, {1})', combine='bitor({0}, {1})')
     elif type_.endswith(':constant'):
         return self.get_value_constant(value).get_matlab_source()
     else:
         return str(value)
コード例 #8
0
 def helper(value):
     if type_ == 'float':
         return common.format_float(value)
     elif type_ == 'bool':
         return str(bool(value)).lower()
     elif type_ == 'char':
         return "'{0}'".format(value.replace("'", "\\'"))
     elif type_ == 'string':
         return '"{0}".to_string()'.format(value.replace('"', '\\"'))
     elif ':bitmask:' in type_:
         return common.make_c_like_bitmask(value)
     elif type_.endswith(':constant'):
         return self.get_value_constant(value).get_rust_source()
     else:
         return str(value)
コード例 #9
0
 def helper(value):
     if type_ == 'float':
         return common.format_float(value)
     elif type_ == 'bool':
         return str(bool(value)).lower()
     elif type_ in ['char', 'string']:
         return "'{0}'".format(value.replace("'", "''"))
     elif ':bitmask:' in type_:
         return common.make_c_like_bitmask(value,
                                           shift='{0} shl {1}',
                                           combine='({0}) or ({1})')
     elif type_.endswith(':constant'):
         return self.get_value_constant(value).get_delphi_source()
     else:
         return str(value)
コード例 #10
0
 def helper(value):
     if type_ == 'float':
         return common.format_float(value)
     elif type_ == 'bool':
         return str(bool(value))
     elif type_ == 'char':
         return '"{0}"C'.format(value.replace('"', '""'))
     elif type_ == 'string':
         return '"{0}"'.format(value.replace('"', '""'))
     elif ':bitmask:' in type_:
         return common.make_c_like_bitmask(value,
                                           combine='({0}) or ({1})')
     elif type_.endswith(':constant'):
         return self.get_value_constant(value).get_vbnet_source()
     else:
         return str(value)
コード例 #11
0
        def helper(value):
            constant = self.get_value_constant(value)

            if constant != None:
                return '{0}-{1}'.format(
                    constant.get_constant_group().get_name().dash,
                    constant.get_name().dash)

            if type_ == 'float':
                return common.format_float(value)
            elif type_ == 'bool':
                return str(bool(value)).lower()
            elif type_ == 'char':
                return '"{0}"'.format(value)  # FIXME: how to escape quotes?
            elif type_ == 'string':
                return '"{0}"'.format(value)  # FIXME: how to escape quotes?
            elif ':bitmask:' in type_:
                return str(value)
            else:
                return str(value)
コード例 #12
0
    def format_value(self, value):
        if isinstance(value, list):
            result = []

            for subvalue in value:
                result.append(self.format_value(subvalue))

            return '{{{0}}}'.format(', '.join(result))

        type_ = self.get_type()

        if type_ == 'float':
            return common.format_float(value)

        if type_ == 'bool':
            return str(bool(value))[0]

        if type_ in ['char', 'string']:
            return '"{0}"'.format(value.replace('"', '\\"'))

        return str(value)
コード例 #13
0
ファイル: php_common.py プロジェクト: pfuxs/generators
    def format_value(self, value):
        if isinstance(value, list):
            result = []

            for subvalue in value:
                result.append(self.format_value(subvalue))

            return 'array({0})'.format(', '.join(result))

        type_ = self.get_type()

        if type_ == 'float':
            return common.format_float(value)

        if type_ == 'bool':
            return str(bool(value)).upper()

        if type_ in ['char', 'string']:
            return "'{0}'".format(value.replace("'", "\\'"))

        return str(value)
コード例 #14
0
    def format_value(self, value):
        if isinstance(value, list):
            result = []

            for subvalue in value:
                result.append(self.format_value(subvalue))

            return '{{{0}}}'.format(', '.join(result))

        type_ = self.get_type()

        if type_ == 'float':
            return common.format_float(value) + 'f'

        if type_ == 'bool':
            return str(bool(value)).lower()

        if type_ == 'char':
            return "'{0}'".format(value.replace("'", "\\'"))

        if type_ == 'string':
            return '"{0}"'.format(value.replace('"', '\\"'))

        return str(value)