Home » Community » U++ community news and announcements » decode
decode [message #39495] |
Sat, 23 March 2013 11:10 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
New small utility function 'decode' serves to convert some particular values to other values as demostrated by this testing code:
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
ASSERT(decode(0, 1, "one", 2, "two", 3, "three", "unknown") == String("unknown"));
ASSERT(decode(1, 1, "one", 2, "two", 3, "three", "unknown") == String("one"));
ASSERT(decode(2, 1, "one", 2, "two", 3, "three", "unknown") == String("two"));
ASSERT(decode(3, 1, "one", 2, "two", 3, "three", "unknown") == String("three"));
ASSERT(decode(3, 1, "one", 2, "two", 3.0, "three", "unknown") == String("three"));
ASSERT(decode(4, 1, "one", 2, "two", 3, "three", "unknown") == String("unknown"));
String s = "3";
ASSERT(decode(s, "3", 3, -1) == 3);
ASSERT(decode(s, "4", 3, -1) == -1);
}
|
|
|
Goto Forum:
Current Time: Tue Apr 23 16:38:41 CEST 2024
Total time taken to generate the page: 0.01672 seconds
|