[gi-docgen/string-macros] Quote string constant values




commit da8a6af1aa2fa39fe6201236a279724d985396fe
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Sun May 22 14:06:00 2022 +0100

    Quote string constant values
    
    Constant values in the GIR are bare, so we need to quote them back for
    their declaration, if they are strings.
    
    Fixes: #128

 gidocgen/gdgenerate.py | 4 ++++
 1 file changed, 4 insertions(+)
---
diff --git a/gidocgen/gdgenerate.py b/gidocgen/gdgenerate.py
index 4693a7e..2260eb5 100644
--- a/gidocgen/gdgenerate.py
+++ b/gidocgen/gdgenerate.py
@@ -344,6 +344,7 @@ class TemplateConstant:
     def __init__(self, namespace, const):
         self.value = const.value
         self.identifier = const.ctype
+        self.type_name = const.target.name
         self.type_cname = const.target.ctype
         self.namespace = namespace.name
         self.name = const.name
@@ -377,6 +378,9 @@ class TemplateConstant:
 
     @property
     def c_decl(self):
+        # String constants are unquoted in the GIR
+        if self.type_name in ["utf8", "filename"]:
+            return utils.code_highlight(f'#define {self.identifier} "{self.value}"')
         return utils.code_highlight(f"#define {self.identifier} {self.value}")
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]