Utilities

Procedures

g-studly-caps-expand
g-name->name
g-name->class-name
g-name->short-name
class-name->name
class-name->g-name
name->g-name
syntax-name->method-name
gi-type-tag->ffi
gi-type-tag->init-val

Description

G-Golf utilities low level API.

Procedures

Procedure: g-studly-caps-expand str

Returns a string34.

Expand the StudlyCaps str to a more schemey-form, according to the conventions of GLib libraries. For example:

(g-studly-caps-expand "GStudlyCapsExpand")
⇒ "g-studly-caps-expand"

(g-studly-caps-expand "GSource")
⇒ "g-source"

(g-studly-caps-expand "GtkIMContext")
⇒ "im-context"

G-Golf slightly modified the original code to also allow the possibility to specially treat the str (expanded) tokens, such as:

(g-studly-caps-expand "WebKitWebContext")
⇒ "webkit-web-context" ;; not "web-kit-web-context"

The list of StudlyCaps token exception pairs are maintained in the g-studly-caps-expand-token-exception alist.

Procedure: g-name->name g-name [as-string? #f]
Procedure: g-name->class-name g-name [as-string? #f]

Return a symbol name, or a string name if as-string is #t.

g-name->name first obtains, the scheme representation of g-name, as a string, by looking for a possible entry in g-name-transform-exception, or if it failed, by calling g-studly-caps-expand.

If the optional as-string argument is #t, it returns that string, otherwise, it calls and returns the result of string->symbol.

g-name->class-name calls g-name->name, surrounds the result using #\< and #\> characters then either return that string, if as-string? is #t, otherwise it calls and returns the result of string->symbol:

(g-name->class-name "GtkWindow")
⇒ <gtk-window>
Procedure: g-name->short-name g-name g-class-name [as-string? #f]

Return a symbol name, or a string name if as-string is #t.

Obtains and returns a (method) short name for g-name. It first obtains the sro (scheme representation of) both g-name and g-class-name (which is expected to be the upstream method container (class) name), as a string, then:

  • if the sro g-class-name is (fully) contained in the sro g-name, it drops the sro g-class-name prefix - or its plural form - and its trailing #\- (hiphen) delimiter from the sro g-name;

  • otherwise, it drops the longest common sro string prefix it finds.

If the optional as-string argument is #t, it returns that string, otherwise, it calls and returns the result of string->symbol.

To illustrate, here is an example for each of the three above exposed cases:

(g-name->shortname "gdk_event_get_event_type" "GdkEvent")
⇒ get-event-type

(g-name->shortname "gdk_events_get_angle" "GdkEvent")
⇒ get-angle

(g-name->short-name "gtk_drag_begin" "GtkWidget")
⇒ drag-begin
Procedure: class-name->name class-name

Returns a (symbol) name.

Obtains and returns the (symbol) name for class-name, by dropping the surrounding '<' and '>' characters. For example:

(class-name->name '<foo-bar>)
⇒ 'foo-bar
Procedure: class-name->g-name class-name

Returns a string.

Obtains and returns the StudlyCaps string reprentation for class-name. For example:

(class-name->g-name '<foo-bar>)
⇒ "FooBar"
Procedure: name->g-name name [as-string? #f]

Return a symbol, or a string if as-string is #t.

Unless name is a string, it first calls (symbol->string name), then changes all occurrences of - (hyphen) to _ (underscore) (other characters are not valid in a g-name).

If the optional as-string argument is #t, it returns that string, otherwise, it calls and returns the result of string->symbol.

Procedure: syntax-name->method-name name

Returns a (symbol) name.

This procedure is used to ‘protect’ syntax names, from being redefined as generic functions and methods.

Users should normally not call this procedure - except for testing purposes, if/when they customize its default settings - it is appropriately and automatically called by G-Golf when importing a GI typelib.

Here is what it does:

  • it first checks if a renamer is available, by calling syntax-name-protect-renamer, and if so, calls it passing name and returns the result;

  • if no renamer is available, it checks if either or both syntax-name-protect-prefix and syntax-name-protect-postfix is(are) available, calls symbol-append adequately passing either or both and name and returns the result.

  • It will raise an exception if none of the syntax name protect prefix, postfix and renamer is available.

See Customization Square - GI Syntax Name Protect. G-Golf GI Syntax Name Protect default values are:

syntax-name-protect-prefix#f
syntax-name-protect-postfix'_(the symbol _)
syntax-name-protect-renamer#f

As an example, using these default settings, the method short name for gcr-secret-exchange-begin would be begin_.

Procedure: gi-type-tag->ffi type-tag

Returns an integer or '* (the symbol *).

Obtains the correponding Guile’s ffi tag value for type-tag, which must be a member of %gi-type-tag. If type-tag is unknown, an exception is raised. Note that Guile’s ffi tag values are integers or '* (the symbol *, used by convention to denote pointer types.

Procedure: gi-type-tag->init-val type-tag

Returns the default init value for type-tag.

Obtains and returns the default init value for type-tag, which will either be 0 (zero), or %null-pointer.


Footnotes

(34)

This procedure, as well as g-name->name and g-name->class-name come from Guile-GNOME, where there are named GStudlyCapsExpand, gtype-name->scm-name and gtype-name->class-name.

In G-Golf, these procedures are also be used to transform other (GObject Introspection) names, such as function names, hence they use the g-name-> prefix instead