IupText MASK attribute for hex string input - iup

What should be the mask for iupText attribute MASK for entering a hexadecimal string of a certain length, for example, the 16-character sequence like 5A18F077D90ABB39?
All I could think of was 16 times [0-9a-fA-F].

The mask "[0-9a-fA-F]+" will do the job for repeating the pattern. Setting also NC=16 attribute restricts the number of characters.

Related

shorten chinesse string to fit in character array C++

I am trying to fit pinyin string in character array. for example If I have pinyin string like below.
string str = "转换汉字为拼音音"; // needs at least 25 bytes to store
char destination[22];
strncpy(destination, str.c_str(), 20);
destination[21] = '\0';
since Chinese characters takes 3 bytes i can do strncpy(destination, str.c_str(), (20/3)*3); but if str contains any character other than Chinese (that takes 2 bytes of 4 bytes in utf8 encoding) this logic will fill.
Later If i try to convert destination to print pinyin characters, only first 6 Chinese characters are printed properly and 2 bytes are printed in hexadecimal.
Is there any way, I can shorten the string before copying to destination so that when destination is printed, proper Chinese characters are printed (without any individual hex bytes)? using POCO::Textendcoing or POCO::UTF8Encoding class?
Thanks in Advance.
Nothing short of creating own way to encode text would work. But even in that case you would have to create 25 characters (don't forget zero at end!) array to store string at end to be printed properly, unless you create own printing routines.
I.e. amount of work required doesn't balance out win of extra 3 bytes.
Note, that code is practically C. In C++ you don't use that style of code.

FreeMarker convert string with commas to number

I need to convert a locale specific string value having either commas or dot in between to indicate thousands separator, to a number in FreeMarker by removing the decimal places. For example: 13,456.79 to 13,456 OR 23.675,98 to 23.675
Using ?number throws exception saying this string can't be converted to a number. I see a similar question here:
Convert string with commas into integer in Freemarker but no solution exist. Is there a way to do so?
I would parse the variable as Integer before (in the Controller/Business layer) exposing it to the template (and react in case of problems with the format).
In my opinion templates should handle nothing more than the presentation of (valid) data.
Alternately...
You can try to transform the string...
<#function string_to_int s >
<#local a = s?replace(",", "") >
<#return a?keep_before_last(".") />
</#function>
${string_to_int("13,456.79")}
will output
13456
Given the limitations like locale specific numbers where decimal and thousands separator characters can either be a dot or a comma, and since I only needed to display the value and not do any numeric calculations based on the number value, I resolved this by simply ignoring the last 3 characters of the string using substring. This will remove the decimal separator and 2 decimal places (assumption being that there are always 2 decimal places).

How to control the width of ZPL alphanumeric code 128 barcode

I am printing a code 128 barcode in ZPL, which must be 78mm. The following numeric barcode works as expected:
^XA^FO141,330^BY3,3,^BCR,243,Y,N,N,A^FD12001752107481808006410360011596^FS^XZ
But changing one number to 'X' near the end of the barcode, means the barcode is now printed as 91mm:
^XA^FO141,330^BY3,3,^BCR,243,Y,N,N,A^FD1200175210748180800641036001X596^FS^XZ
Changing the barcode module with from 3 to 2 with ^BY2 makes the barcode 60mm which is not acceptable.
Any suggestions?
Code 128 has different Subtypes. One of them can encode two numbers in one barcode-character. Your Zebra optimizes your barcode because you use the
^BCo,h,f,g,e,m
Command with Parameter m = mode set to
A = Automatic Mode
This analyzes the data sent and automatically
determines the best packing method. The full
ASCII character set can be used in the ^FD
statement — the printer determines when to shift
subsets. A string of four or more numeric digits
causes an automatic shift to Subset C.
Switching modes and printing alphanumeric makes your barcode longer.

Padding for SecureRandom and URLsafe

I am trying to find a way to create a padding for a key created using:
SecureRandom.urlsafe_base64(8). I know I can pass a second argument stating that I want a padding, but according to the docs:
The boolean argument padding specifies the padding. If it is false or
nil, padding is not generated. Otherwise padding is generated. By
default, padding is not generated because “=” may be used as a URL
delimiter.
So, my question is. How could I add a padding (that is url safe) so I know when is the string finished? (I need to concat two of those strings)
from the documentation:
The result may contain A-Z, a-z, 0-9, “-” and “_”
so you could use any other character for your delimiter, like + for example (which is a url-encoded space)

Make UUID shorter (Hex to ASCII conversion)

In my web application one model uses identifier that was generated by some UUID tool. As I want that identifier to be part of the URL I am investigating methods to shorten that UUID string. As it is currently is in hexadecimal format I thought about converting it to ASCII somehow. As it should afterwards only contain normal characters and number ([\d\w]+) the normal hex to ASCII conversion doesn't seem to work (ugly characters).
Do you know of some nice algorithm or tool (Ruby) to do that?
A UUID is a 128-bit binary number, in the end. If you represent it as 16 unencoded bytes, there's no way to avoid "ugly characters". What you probably want to do is decode it from hex and then encode it using base64. Note that base64 encoding uses the characters + / = as well as A-Za-z0-9, you'll want to do a little postprocessing (I suggest s/+/-/g; s/\//_/g; s/==$// -- a base64ed UUID will always end with two equals signs)

Resources