[yast-commit] r67521 - in /trunk/core: ./ libycp/src/ libycp/testsuite/tests/builtin/ package/
Author: aschnell Date: Wed Feb 22 15:19:20 2012 New Revision: 67521 URL: http://svn.opensuse.org/viewcvs/yast?rev=67521&view=rev Log: - added tointeger builtin with explicite base qualification Modified: trunk/core/VERSION trunk/core/libycp/src/YCPBuiltinInteger.cc trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.err trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.out trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.ycp trunk/core/package/yast2-core.changes Modified: trunk/core/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/VERSION?rev=67521&r1=67520&r2=67521&view=diff ============================================================================== --- trunk/core/VERSION (original) +++ trunk/core/VERSION Wed Feb 22 15:19:20 2012 @@ -1 +1 @@ -2.22.3 +2.22.4 Modified: trunk/core/libycp/src/YCPBuiltinInteger.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/src/YCPBuiltinInteger.cc?rev=67521&r1=67520&r2=67521&view=diff ============================================================================== --- trunk/core/libycp/src/YCPBuiltinInteger.cc (original) +++ trunk/core/libycp/src/YCPBuiltinInteger.cc Wed Feb 22 15:19:20 2012 @@ -18,6 +18,8 @@ /-*/ +#include <sstream> + #include "ycp/YCPBuiltinInteger.h" #include "ycp/YCPInteger.h" #include "ycp/YCPString.h" @@ -40,7 +42,7 @@ * 1 + 2 -> 3 * </pre> */ - + if (i1.isNull () || i2.isNull ()) return YCPNull (); @@ -264,15 +266,16 @@ static YCPValue -i_tointeger (const YCPValue &v) +i_tointeger1(const YCPValue &v) { /** * @builtin tointeger + * @id tointeger-1 * @short Converts a value to an integer. * @description * If the value can't be converted to an integer, nil is returned. * @param any VALUE - * @return integer + * @return integer * * @usage tointeger (4.03) -> 4 * @usage tointeger ("42") -> 42 @@ -305,6 +308,48 @@ } +static YCPValue +i_tointeger2(const YCPString& v, const YCPInteger& b) +{ + /** + * @builtin tointeger + * @id tointeger-2 + * @short Converts a string to an integer. + * @description + * If the value can't be converted to an integer, nil is returned. + * @param string value + * @param integer base + * @return integer + * + * @usage tointeger("20", 8) -> 8 + * @usage tointeger("20", 10) -> 20 + * @usage tointeger("20", 16) -> 32 + * @usage tointeger("0x20", 16) -> 32 + */ + + std::istringstream s(v->value_cstr()); + s.imbue(std::locale::classic()); + + switch (b->value()) + { + case 8: s >> std::oct; break; + case 10: s >> std::dec; break; + case 16: s >> std::hex; break; + + default: + return YCPNull(); + } + + long long int i; + s >> i; + + if (s.fail() || !s.eof()) + return YCPNull(); + + return YCPInteger(i); +} + + YCPBuiltinInteger::YCPBuiltinInteger () { // must be static, registerDeclarations saves a pointer to it! @@ -323,7 +368,8 @@ { "<<", "integer (integer, integer)", (void *)i_left, ETC }, { ">>", "integer (integer, integer)", (void *)i_right, ETC }, { "~", "integer (integer)", (void *)i_bnot, ETC }, - { "tointeger", "integer (const any)", (void *)i_tointeger,ETC }, + { "tointeger", "integer (const any)", (void *)i_tointeger1, ETC }, + { "tointeger", "integer (string, integer)", (void *)i_tointeger2, ETC }, { NULL, NULL, NULL, ETC } #undef ETC #undef ETCf Modified: trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.err URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.err?rev=67521&r1=67520&r2=67521&view=diff ============================================================================== --- trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.err (original) +++ trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.err Wed Feb 22 15:19:20 2012 @@ -161,3 +161,55 @@ (tointeger ("foo") == nil) ---------------------------------------------------------------------- [Interpreter] tests/builtin/Builtin-Integer.ycp:74 Cannot convert 'foo' to an integer +Parsed: +---------------------------------------------------------------------- +"** conversions with explicite base **" +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("1", 8) == 1) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("1", 10) == 1) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("1", 16) == 1) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("10", 8) == 8) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("10", 10) == 10) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("10", 16) == 16) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("010", 8) == 8) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("010", 10) == 10) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("010", 16) == 16) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("0x10", 8) == nil) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("0x10", 10) == nil) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(tointeger ("0x10", 16) == 16) +---------------------------------------------------------------------- Modified: trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.out URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.out?rev=67521&r1=67520&r2=67521&view=diff ============================================================================== --- trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.out (original) +++ trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.out Wed Feb 22 15:19:20 2012 @@ -38,3 +38,16 @@ (true) (true) (true) +("** conversions with explicite base **") +(true) +(true) +(true) +(true) +(true) +(true) +(true) +(true) +(true) +(true) +(true) +(true) Modified: trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.ycp?rev=67521&r1=67520&r2=67521&view=diff ============================================================================== --- trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.ycp (original) +++ trunk/core/libycp/testsuite/tests/builtin/Builtin-Integer.ycp Wed Feb 22 15:19:20 2012 @@ -72,3 +72,20 @@ (tointeger ("042") == 34) (tointeger ("") == nil) (tointeger ("foo") == nil) + + +("** conversions with explicite base **") + +(tointeger ("1", 8) == 1) +(tointeger ("1", 10) == 1) +(tointeger ("1", 16) == 1) +(tointeger ("10", 8) == 8) +(tointeger ("10", 10) == 10) +(tointeger ("10", 16) == 16) +(tointeger ("010", 8) == 8) +(tointeger ("010", 10) == 10) +(tointeger ("010", 16) == 16) +(tointeger ("0x10", 8) == nil) +(tointeger ("0x10", 10) == nil) +(tointeger ("0x10", 16) == 16) + Modified: trunk/core/package/yast2-core.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/package/yast2-core.changes?rev=67521&r1=67520&r2=67521&view=diff ============================================================================== --- trunk/core/package/yast2-core.changes (original) +++ trunk/core/package/yast2-core.changes Wed Feb 22 15:19:20 2012 @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Wed Feb 22 14:59:37 CET 2012 - aschnell@suse.de + +- added tointeger builtin with explicite base qualification +- 2.22.4 + +------------------------------------------------------------------- Fri Feb 3 14:36:31 CET 2012 - mvidner@suse.cz - ini-agent: only change permissions of new files (bnc#743355) -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
aschnell@svn2.opensuse.org