[gnome-shell] format: support %Id conversion characters in format.js
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] format: support %Id conversion characters in format.js
- Date: Thu, 29 Mar 2012 21:30:13 +0000 (UTC)
commit 6d82aefad4ddc8302913a2986780d7cd7f541125
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Thu Mar 29 15:29:48 2012 -0400
format: support %Id conversion characters in format.js
This is needed for languages which translate numbers with an
alternative representation, such as Persian.
https://bugzilla.gnome.org/show_bug.cgi?id=673106
js/misc/format.js | 15 +++++++++++++--
src/shell-util.c | 12 ++++++++++++
src/shell-util.h | 3 +++
3 files changed, 28 insertions(+), 2 deletions(-)
---
diff --git a/js/misc/format.js b/js/misc/format.js
index 54320c0..74972ac 100644
--- a/js/misc/format.js
+++ b/js/misc/format.js
@@ -1,5 +1,7 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+const Shell = imports.gi.Shell;
+
/*
* This function is intended to extend the String object and provide
* an String.format API for string formatting.
@@ -17,11 +19,16 @@ function format() {
let i = 0;
let args = arguments;
- return str.replace(/%([0-9]+)?(?:\.([0-9]+))?(.)/g, function (str, widthGroup, precisionGroup, genericGroup) {
+ return str.replace(/%(I+)?([0-9]+)?(?:\.([0-9]+))?(.)/g, function (str, flagsGroup, widthGroup, precisionGroup, genericGroup) {
if (precisionGroup != '' && genericGroup != 'f')
throw new Error("Precision can only be specified for 'f'");
+ let hasAlternativeIntFlag = (flagsGroup.indexOf('I') != -1);
+
+ if (hasAlternativeIntFlag && genericGroup != 'd')
+ throw new Error("Alternative output digits can only be specfied for 'd'");
+
let fillChar = (widthGroup[0] == '0') ? '0' : ' ';
let width = parseInt(widthGroup, 10) || 0;
@@ -41,7 +48,11 @@ function format() {
s = args[i++].toString();
break;
case 'd':
- s = parseInt(args[i++]).toString();
+ let intV = parseInt(args[i++]);
+ if (hasAlternativeIntFlag)
+ s = Shell.format_int_alternative_output(intV);
+ else
+ s = intV.toString();
break;
case 'x':
s = parseInt(args[i++]).toString(16);
diff --git a/src/shell-util.c b/src/shell-util.c
index 0a1baab..e7be812 100644
--- a/src/shell-util.c
+++ b/src/shell-util.c
@@ -868,3 +868,15 @@ shell_util_wifexited (int status,
return ret;
}
+
+/**
+ * shell_format_int_alternative_output:
+ * @intval:
+ *
+ * Returns: (transfer full):
+ */
+gchar *
+shell_format_int_alternative_output (gint intval)
+{
+ return g_strdup_printf ("%Id", intval);
+}
diff --git a/src/shell-util.h b/src/shell-util.h
index bfb5089..2b21886 100644
--- a/src/shell-util.h
+++ b/src/shell-util.h
@@ -52,6 +52,9 @@ gboolean shell_session_is_active_for_systemd (void);
gboolean shell_util_wifexited (int status,
int *exit);
+gchar *shell_format_int_alternative_output (gint intval);
+
+
G_END_DECLS
#endif /* __SHELL_UTIL_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]