1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 1998-2008, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
13 * Modification History:
15 * Date Name Description
16 * 06/10/99 stephen Creation.
17 * 02/07/08 Spieth Correct XLIFF generation on EBCDIC platform
19 *******************************************************************************
22 #include "unicode/putil.h"
28 /* go from "/usr/local/include/curses.h" to "/usr/local/include" */
30 get_dirname(char *dirname,
33 const char *lastSlash = uprv_strrchr(filename, U_FILE_SEP_CHAR) + 1;
35 if(lastSlash>filename) {
36 uprv_strncpy(dirname, filename, (lastSlash - filename));
37 *(dirname + (lastSlash - filename)) = '\0';
43 /* go from "/usr/local/include/curses.h" to "curses" */
45 get_basename(char *basename,
48 /* strip off any leading directory portions */
49 const char *lastSlash = uprv_strrchr(filename, U_FILE_SEP_CHAR) + 1;
52 if(lastSlash>filename) {
53 uprv_strcpy(basename, lastSlash);
55 uprv_strcpy(basename, filename);
58 /* strip off any suffix */
59 lastDot = uprv_strrchr(basename, '.');
68 itostr(char * buffer, int32_t i, uint32_t radix, int32_t pad)
70 const char digits[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
78 /* if i is negative make it positive */
84 digit = (int)(i % radix);
85 buffer[length++]= digits[digit];
90 buffer[length++] = '0';/*zero padding */
93 /* if i is negative add the negative sign */
98 /* null terminate the buffer */
99 if(length<MAX_DIGITS){
100 buffer[length] = 0x0000;
103 num= (pad>=length) ? pad :length;
106 /* Reverses the string */
107 for (j = 0; j < (num / 2); j++){
108 temp = buffer[(length-1) - j];
109 buffer[(length-1) - j] = buffer[j];