From 9c8f6849c3580654490c5467bcb67b06e6cf514f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 4 Mar 2018 11:15:18 -0500 Subject: [PATCH] Synced const-correctness in ui_attrstr.h to attrstr.c, propagated that to the necessary private functions, and added some references to testing.h. --- _future/unittest/testing.h | 4 ++++ common/attrlist.c | 2 +- common/attrstr.c | 22 +++++++++++----------- common/attrstr.h | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/_future/unittest/testing.h b/_future/unittest/testing.h index 15ea2629..c2d81690 100644 --- a/_future/unittest/testing.h +++ b/_future/unittest/testing.h @@ -43,6 +43,10 @@ extern "C" { static inline void testingprivScaffold ## name(testingT *t) { name(t); } #endif +// references: +// - https://gitlab.gnome.org/GNOME/glib/blob/master/glib/gconstructor.h +// - https://gitlab.gnome.org/GNOME/glib/blob/master/gio/glib-compile-resources.c +// - https://msdn.microsoft.com/en-us/library/bb918180.aspx #if defined(__cplusplus) #define testingprivMkCtor(name, reg) \ static reg ## Class testingprivCtor ## name(#name, testingprivScaffold ## name); diff --git a/common/attrlist.c b/common/attrlist.c index 7a85aff9..377778eb 100644 --- a/common/attrlist.c +++ b/common/attrlist.c @@ -598,7 +598,7 @@ void uiprivAttrListRemoveCharacters(uiprivAttrList *alist, size_t start, size_t a = attrDeleteRange(alist, a, start, end); } -void uiprivAttrListForEach(uiprivAttrList *alist, uiAttributedString *s, uiAttributedStringForEachAttributeFunc f, void *data) +void uiprivAttrListForEach(const uiprivAttrList *alist, const uiAttributedString *s, uiAttributedStringForEachAttributeFunc f, void *data) { struct attr *a; uiForEach ret; diff --git a/common/attrstr.c b/common/attrstr.c index 73246651..ab3f073a 100644 --- a/common/attrstr.c +++ b/common/attrstr.c @@ -279,6 +279,17 @@ void uiAttributedStringDelete(uiAttributedString *s, size_t start, size_t end) resize(s, start + count, start16 + count16); } +void uiAttributedStringSetAttribute(uiAttributedString *s, uiAttributeSpec *spec, size_t start, size_t end) +{ + uiprivAttrListInsertAttribute(s->attrs, spec, start, end); +} + +// LONGTERM introduce an iterator object instead? +void uiAttributedStringForEachAttribute(const uiAttributedString *s, uiAttributedStringForEachAttributeFunc f, void *data) +{ + uiprivAttrListForEach(s->attrs, s, f, data); +} + // TODO figure out if we should count the grapheme past the end size_t uiAttributedStringNumGraphemes(uiAttributedString *s) { @@ -303,17 +314,6 @@ size_t uiAttributedStringGraphemeToByteIndex(uiAttributedString *s, size_t pos) return pos; } -void uiAttributedStringSetAttribute(uiAttributedString *s, uiAttributeSpec *spec, size_t start, size_t end) -{ - uiprivAttrListInsertAttribute(s->attrs, spec, start, end); -} - -// LONGTERM introduce an iterator object instead? -void uiAttributedStringForEachAttribute(uiAttributedString *s, uiAttributedStringForEachAttributeFunc f, void *data) -{ - uiprivAttrListForEach(s->attrs, s, f, data); -} - // helpers for platform-specific code const uint16_t *uiprivAttributedStringUTF16String(uiAttributedString *s) diff --git a/common/attrstr.h b/common/attrstr.h index b0192b92..32e632ed 100644 --- a/common/attrstr.h +++ b/common/attrstr.h @@ -18,7 +18,7 @@ extern void uiprivAttrListInsertCharactersExtendingAttributes(uiprivAttrList *al extern void uiprivAttrListRemoveAttribute(uiprivAttrList *alist, uiAttribute type, size_t start, size_t end); extern void uiprivAttrListRemoveAttributes(uiprivAttrList *alist, size_t start, size_t end); extern void uiprivAttrListRemoveCharacters(uiprivAttrList *alist, size_t start, size_t end); -extern void uiprivAttrListForEach(uiprivAttrList *alist, uiAttributedString *s, uiAttributedStringForEachAttributeFunc f, void *data); +extern void uiprivAttrListForEach(const uiprivAttrList *alist, const uiAttributedString *s, uiAttributedStringForEachAttributeFunc f, void *data); // attrstr.c extern const uint16_t *uiprivAttributedStringUTF16String(uiAttributedString *s);