1 module PixelPerfectEngine.system.etc; 2 3 import std.conv; 4 import std.algorithm.mutation; 5 /* 6 * Copyright (C) 2015-2017, by Laszlo Szeremi under the Boost license. 7 * 8 * Pixel Perfect Engine, etc module 9 */ 10 11 12 13 public wstring[] stringArrayConv(string[] s){ 14 wstring[] result; 15 foreach(ss; s){ 16 wstring ws; 17 foreach(c; ss){ 18 ws ~= c; 19 } 20 result ~= ws; 21 } 22 return result; 23 } 24 string intToHex(int i, int format = 0){ 25 string result; 26 do{ 27 switch(i & 0x000F){ 28 case 1: result ~='1'; break; 29 case 2: result ~='2'; break; 30 case 3: result ~='3'; break; 31 case 4: result ~='4'; break; 32 case 5: result ~='5'; break; 33 case 6: result ~='6'; break; 34 case 7: result ~='7'; break; 35 case 8: result ~='8'; break; 36 case 9: result ~='9'; break; 37 case 10: result ~='A'; break; 38 case 11: result ~='B'; break; 39 case 12: result ~='C'; break; 40 case 13: result ~='D'; break; 41 case 14: result ~='E'; break; 42 case 15: result ~='F'; break; 43 default: result ~='0'; break; 44 } 45 i = i / 16; 46 }while(i > 0); 47 if(result.length < format){ 48 for(int j = result.length ; j < format ; j++){ 49 result ~= '0'; 50 } 51 } 52 reverse(cast(char[])result); 53 return result; 54 } 55 string intToOct(int i, int format){ 56 string result; 57 do{ 58 switch(i & 0x0007){ 59 case 1: result ~='1'; break; 60 case 2: result ~='2'; break; 61 case 3: result ~='3'; break; 62 case 4: result ~='4'; break; 63 case 5: result ~='5'; break; 64 case 6: result ~='6'; break; 65 case 7: result ~='7'; break; 66 default: result ~='0'; break; 67 } 68 i = i / 8; 69 }while(i > 0); 70 if(result.length < format){ 71 for(int j = result.length ; j < format ; j++){ 72 result ~= '0'; 73 } 74 } 75 reverse(cast(char[])result); 76 return result; 77 } 78 int parseHex(string s){ 79 //std.stdio.writeln(s); 80 int result; 81 for(int i ; i < s.length; i++){ 82 result *= 16; 83 switch(s[i]){ 84 case '0': break; 85 case '1': result += 1; break; 86 case '2': result += 2; break; 87 case '3': result += 3; break; 88 case '4': result += 4; break; 89 case '5': result += 5; break; 90 case '6': result += 6; break; 91 case '7': result += 7; break; 92 case '8': result += 8; break; 93 case '9': result += 9; break; 94 case 'a','A': result += 10; break; 95 case 'b','B': result += 11; break; 96 case 'c','C': result += 12; break; 97 case 'd','D': result += 13; break; 98 case 'e','E': result += 14; break; 99 case 'f','F': result += 15; break; 100 default: throw new Exception("String cannot be parsed!"); 101 } 102 } 103 return result; 104 }