[gnome-2048] Move a method.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-2048] Move a method.
- Date: Fri, 15 Nov 2019 13:53:47 +0000 (UTC)
commit e0769881440454f49af3a0c0dc8f72c849c48ca1
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri Nov 15 14:09:43 2019 +0100
Move a method.
src/application.vala | 42 +-----------------------------------------
src/cli.vala | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 41 deletions(-)
---
diff --git a/src/application.vala b/src/application.vala
index f402e65..a749a59 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -116,7 +116,7 @@ private class TwentyFortyEight : Gtk.Application
return Posix.EXIT_SUCCESS;
}
- if (size != null && !parse_size ((!) size, out cols, out rows))
+ if (size != null && !CLI.parse_size ((!) size, out cols, out rows))
{
/* Translators: command-line error message, displayed for an incorrect game size request; try
'gnome-2048 -s 0' */
stderr.printf ("%s\n", _("Failed to parse size. Size must be between 2 and 9, or in the form
2x3."));
@@ -146,46 +146,6 @@ private class TwentyFortyEight : Gtk.Application
/* Activate */
return -1;
}
- private static bool parse_size (string size, out uint8 cols, out uint8 rows)
- {
- cols = 0; // garbage
- rows = 0; // garbage
-
- /* size is either a digit, either of the for MxN */
- string [] tokens = size.split ("x");
- if (tokens.length == 0 || tokens.length > 2)
- return false;
-
- /* parse the first token in any case */
- uint64 test;
- if (!uint64.try_parse (tokens [0], out test))
- return false;
- if (test <= 0 || test > 9)
- return false;
- cols = (uint8) test;
-
- /* test for forbidden "1" size and return */
- if (tokens.length == 1)
- {
- if (cols < 2)
- return false;
- rows = cols;
- return true;
- }
-
- /* parse the second token, if any */
- if (!uint64.try_parse (tokens [1], out test))
- return false;
- if (test <= 0 || test > 9)
- return false;
- rows = (uint8) test;
-
- /* test for forbidden sizes, and return */
- if (Grid.is_disallowed_grid_size (ref cols, ref rows))
- return false;
-
- return true;
- }
protected override void startup ()
{
diff --git a/src/cli.vala b/src/cli.vala
index aedb527..5134df8 100644
--- a/src/cli.vala
+++ b/src/cli.vala
@@ -254,4 +254,49 @@ namespace CLI
stdout.printf (board);
}
+
+ /*\
+ * * parse command-line input size
+ \*/
+
+ private static inline bool parse_size (string size, out uint8 cols, out uint8 rows)
+ {
+ cols = 0; // garbage
+ rows = 0; // garbage
+
+ /* size is either a digit, either of the for MxN */
+ string [] tokens = size.split ("x");
+ if (tokens.length == 0 || tokens.length > 2)
+ return false;
+
+ /* parse the first token in any case */
+ uint64 test;
+ if (!uint64.try_parse (tokens [0], out test))
+ return false;
+ if (test <= 0 || test > 9)
+ return false;
+ cols = (uint8) test;
+
+ /* test for forbidden "1" size and return */
+ if (tokens.length == 1)
+ {
+ if (cols < 2)
+ return false;
+ rows = cols;
+ return true;
+ }
+
+ /* parse the second token, if any */
+ if (!uint64.try_parse (tokens [1], out test))
+ return false;
+ if (test <= 0 || test > 9)
+ return false;
+ rows = (uint8) test;
+
+ /* test for forbidden sizes, and return */
+ if (Grid.is_disallowed_grid_size (ref cols, ref rows))
+ return false;
+
+ return true;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]