After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 655185 - [patch] Add string.get_prev_char ()
[patch] Add string.get_prev_char ()
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Basic Types
0.17.x
Other Linux
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-07-23 21:11 UTC by Sébastien Wilmet
Modified: 2012-07-18 09:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch v1 (1.02 KB, patch)
2011-07-23 21:11 UTC, Sébastien Wilmet
none Details | Review
glib-2.0: add string.get_prev_char() (1.03 KB, patch)
2012-07-04 19:44 UTC, Sébastien Wilmet
needs-work Details | Review
glib-2.0: add string.get_prev_char() (1.29 KB, patch)
2012-07-17 01:40 UTC, Sébastien Wilmet
none Details | Review

Description Sébastien Wilmet 2011-07-23 21:11:11 UTC
Created attachment 192539 [details] [review]
Patch v1

Sometimes I need to traverse a string in the reverse order.

Since the method string.get_next_char () already exists and is easy to use, I've made a patch to add the opposite: string.get_prev_char ().
Comment 1 Sébastien Wilmet 2012-07-04 19:44:04 UTC
Created attachment 218046 [details] [review]
glib-2.0: add string.get_prev_char()

This is the opposite of string.get_next_char().
Comment 2 Jürg Billeter 2012-07-16 15:56:55 UTC
Review of attachment 218046 [details] [review]:

Shouldn't get_prev_char() decrement the index before calling utf8_get_char()? Otherwise you have to ignore the first codepoint returned and false is returned one iteration early.
Comment 3 Sébastien Wilmet 2012-07-17 01:38:46 UTC
(In reply to comment #2)
> Review of attachment 218046 [details] [review]:
> 
> Shouldn't get_prev_char() decrement the index before calling utf8_get_char()?
> Otherwise you have to ignore the first codepoint returned and false is returned
> one iteration early.

Yes, indeed it would be more convenient.
Comment 4 Sébastien Wilmet 2012-07-17 01:40:16 UTC
Created attachment 218963 [details] [review]
glib-2.0: add string.get_prev_char()

This is the opposite of string.get_next_char().

There is a difference though, to be more convenient in a loop:

get_next_char() returns the current chararcter, and the next index.
get_prev_char() returns the previous character, and the previous index.
Comment 5 Jürg Billeter 2012-07-18 09:51:34 UTC
commit b4e884c150100d56636d5cf6be4e5311d62bb718
Author: Sébastien Wilmet <swilmet@src.gnome.org>
Date:   Wed Jul 4 21:39:01 2012 +0200

    glib-2.0: add string.get_prev_char()
    
    This is the opposite of string.get_next_char().
    
    There is a difference though, to be more convenient in a loop:
    
    get_next_char() returns the current chararcter, and the next index.
    get_prev_char() returns the previous character, and the previous index.
    
    Fixes bug 655185.