From 13459b6cea34c4c38f65fbcc9df65a4af7bbfe43 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 18 Jun 2019 17:07:10 +0200 Subject: [PATCH 1/2] replace more %xx in mission names --- addons/strings/CfgFunctions.hpp | 1 + addons/strings/fnc_decodeHTML.sqf | 59 +++++++++++++++++++ addons/ui/fnc_initDisplayDiary.sqf | 2 +- addons/ui/fnc_initDisplayMultiplayerSetup.sqf | 2 +- addons/ui/fnc_initDisplayRemoteMissions.sqf | 4 +- 5 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 addons/strings/fnc_decodeHTML.sqf diff --git a/addons/strings/CfgFunctions.hpp b/addons/strings/CfgFunctions.hpp index b48fac451..d6c36c27e 100644 --- a/addons/strings/CfgFunctions.hpp +++ b/addons/strings/CfgFunctions.hpp @@ -16,6 +16,7 @@ class CfgFunctions { PATHTO_FNC(strLen); PATHTO_FNC(trim); PATHTO_FNC(sanitizeHTML); + PATHTO_FNC(decodeHTML); }; }; }; diff --git a/addons/strings/fnc_decodeHTML.sqf b/addons/strings/fnc_decodeHTML.sqf new file mode 100644 index 000000000..ebec16959 --- /dev/null +++ b/addons/strings/fnc_decodeHTML.sqf @@ -0,0 +1,59 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_decodeHTML + +Description: + Reverse HTML encoded text to readable text. + +Parameters: + _string - HTML encoded text + +Returns: + _return - Human readable text + +Examples: + (begin example) + "Mission%20Name" call CBA_fnc_decodeHTML; // "Mission Name" + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +#define UTF8_TABLE [\ + ["%e4","ä"],\ + ["%f6","ö"],\ + ["%fc","ü"],\ + ["%c4","Ä"],\ + ["%d6","Ö"],\ + ["%dc","Ü"],\ + ["%df","ß"],\ + ["%20"," "],\ + ["%21","!"],\ + ["%3F","?"],\ + ["%2e","."],\ + ["%25","%"]\ +] + +params [["_string", "", [""]]]; +if (_string isEqualTo "") exitWith {""}; + +private _cache = missionNamespace getVariable [QGVAR(HTMLCache), objNull]; +private _return = _cache getVariable _string; + +if (isNil "_return") then { + _return = _string; + + { + _return = ([_return] + _x) call CBA_fnc_replace; + } forEach UTF8_TABLE; + + if (isNull _cache) then { + _cache = [] call CBA_fnc_createNamespace; + missionNamespace setVariable [QGVAR(HTMLCache), _cache]; + }; + + _cache setVariable [_string, _return]; +}; + +_return diff --git a/addons/ui/fnc_initDisplayDiary.sqf b/addons/ui/fnc_initDisplayDiary.sqf index 9617d68f2..0adb2afce 100644 --- a/addons/ui/fnc_initDisplayDiary.sqf +++ b/addons/ui/fnc_initDisplayDiary.sqf @@ -5,7 +5,7 @@ _this spawn { params ["_display"]; private _missionName = _display displayCtrl IDC_DIARY_MISSION_NAME; - private _text = [ctrlText _missionName, "%20", " "] call CBA_fnc_replace; + private _text = ctrlText _missionName call CBA_fnc_decodeHTML; _missionName ctrlSetText _text; }; }; diff --git a/addons/ui/fnc_initDisplayMultiplayerSetup.sqf b/addons/ui/fnc_initDisplayMultiplayerSetup.sqf index 188012c61..13630d27a 100644 --- a/addons/ui/fnc_initDisplayMultiplayerSetup.sqf +++ b/addons/ui/fnc_initDisplayMultiplayerSetup.sqf @@ -45,7 +45,7 @@ private _fnc_update = { // replace %20 with space private _missionName = _display displayCtrl IDC_MPSETUP_NAME; - private _text = [ctrlText _missionName, "%20", " "] call (uiNamespace getVariable "CBA_fnc_replace"); + private _text = ctrlText _missionName call (uiNamespace getVariable "CBA_fnc_decodeHTML"); _missionName ctrlSetText _text; }; diff --git a/addons/ui/fnc_initDisplayRemoteMissions.sqf b/addons/ui/fnc_initDisplayRemoteMissions.sqf index 9b15ff0f5..d9fbe9389 100644 --- a/addons/ui/fnc_initDisplayRemoteMissions.sqf +++ b/addons/ui/fnc_initDisplayRemoteMissions.sqf @@ -89,10 +89,10 @@ private _fnc_storeMapMissions = {_this spawn {isNil { // delay a frame private _ctrlMissions = _display displayCtrl IDC_SERVER_MISSION; private _missions = []; - private _fnc_replace = uiNamespace getVariable "CBA_fnc_replace"; + private _fnc_decode = uiNamespace getVariable "CBA_fnc_decodeHTML"; for "_i" from 0 to (lbSize _ctrlMissions - 1) do { - private _name = [_ctrlMissions lbText _i, "%20", " "] call _fnc_replace; // replace %20 with space + private _name = (_ctrlMissions lbText _i) call _fnc_decode; private _value = _ctrlMissions lbValue _i; private _data = _ctrlMissions lbData _i; private _color = _ctrlMissions lbColor _i; From 87dd57cb48588e94a898278b64cbc52d95afc56b Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 21 Jun 2019 00:43:38 +0200 Subject: [PATCH 2/2] update encoding list --- addons/strings/CfgFunctions.hpp | 2 +- .../{fnc_decodeHTML.sqf => fnc_decodeURL.sqf} | 27 +-- addons/strings/script_component.hpp | 219 ++++++++++++++++++ addons/ui/fnc_initDisplayDiary.sqf | 2 +- addons/ui/fnc_initDisplayInterrupt.sqf | 10 + addons/ui/fnc_initDisplayMultiplayerSetup.sqf | 9 +- addons/ui/fnc_initDisplayRemoteMissions.sqf | 8 +- 7 files changed, 249 insertions(+), 28 deletions(-) rename addons/strings/{fnc_decodeHTML.sqf => fnc_decodeURL.sqf} (56%) diff --git a/addons/strings/CfgFunctions.hpp b/addons/strings/CfgFunctions.hpp index d6c36c27e..5afd84a60 100644 --- a/addons/strings/CfgFunctions.hpp +++ b/addons/strings/CfgFunctions.hpp @@ -16,7 +16,7 @@ class CfgFunctions { PATHTO_FNC(strLen); PATHTO_FNC(trim); PATHTO_FNC(sanitizeHTML); - PATHTO_FNC(decodeHTML); + PATHTO_FNC(decodeURL); }; }; }; diff --git a/addons/strings/fnc_decodeHTML.sqf b/addons/strings/fnc_decodeURL.sqf similarity index 56% rename from addons/strings/fnc_decodeHTML.sqf rename to addons/strings/fnc_decodeURL.sqf index ebec16959..d1e67eb52 100644 --- a/addons/strings/fnc_decodeHTML.sqf +++ b/addons/strings/fnc_decodeURL.sqf @@ -1,44 +1,29 @@ #include "script_component.hpp" /* ---------------------------------------------------------------------------- -Function: CBA_fnc_decodeHTML +Function: CBA_fnc_decodeURL Description: - Reverse HTML encoded text to readable text. + Reverse URL encoded text to readable text. Parameters: - _string - HTML encoded text + _string - URL encoded text Returns: _return - Human readable text Examples: (begin example) - "Mission%20Name" call CBA_fnc_decodeHTML; // "Mission Name" + "Mission%20Name" call CBA_fnc_decodeURL; // "Mission Name" (end) Author: commy2 ---------------------------------------------------------------------------- */ -#define UTF8_TABLE [\ - ["%e4","ä"],\ - ["%f6","ö"],\ - ["%fc","ü"],\ - ["%c4","Ä"],\ - ["%d6","Ö"],\ - ["%dc","Ü"],\ - ["%df","ß"],\ - ["%20"," "],\ - ["%21","!"],\ - ["%3F","?"],\ - ["%2e","."],\ - ["%25","%"]\ -] - params [["_string", "", [""]]]; if (_string isEqualTo "") exitWith {""}; -private _cache = missionNamespace getVariable [QGVAR(HTMLCache), objNull]; +private _cache = missionNamespace getVariable [QGVAR(URLCache), objNull]; private _return = _cache getVariable _string; if (isNil "_return") then { @@ -50,7 +35,7 @@ if (isNil "_return") then { if (isNull _cache) then { _cache = [] call CBA_fnc_createNamespace; - missionNamespace setVariable [QGVAR(HTMLCache), _cache]; + missionNamespace setVariable [QGVAR(URLCache), _cache]; }; _cache setVariable [_string, _return]; diff --git a/addons/strings/script_component.hpp b/addons/strings/script_component.hpp index a6a2024e6..2fcca2a76 100644 --- a/addons/strings/script_component.hpp +++ b/addons/strings/script_component.hpp @@ -10,3 +10,222 @@ #endif #include "\x\cba\addons\main\script_macros.hpp" + +#define UTF8_TABLE [\ + ["%21","!"],\ + ["%22",""""],\ + ["%23","#"],\ + ["%24","$"],\ + ["%26","&"],\ + ["%27","'"],\ + ["%28","("],\ + ["%29",")"],\ + ["%2a","*"],\ + ["%2b","+"],\ + ["%2c",","],\ + ["%2d","-"],\ + ["%2e","."],\ + ["%2f","/"],\ + ["%30","0"],\ + ["%31","1"],\ + ["%32","2"],\ + ["%33","3"],\ + ["%34","4"],\ + ["%35","5"],\ + ["%36","6"],\ + ["%37","7"],\ + ["%38","8"],\ + ["%39","9"],\ + ["%3a",":"],\ + ["%3b",";"],\ + ["%3c","<"],\ + ["%3d","="],\ + ["%3e",">"],\ + ["%3f","?"],\ + ["%40","@"],\ + ["%41","A"],\ + ["%42","B"],\ + ["%43","C"],\ + ["%44","D"],\ + ["%45","E"],\ + ["%46","F"],\ + ["%47","G"],\ + ["%48","H"],\ + ["%49","I"],\ + ["%4a","J"],\ + ["%4b","K"],\ + ["%4c","L"],\ + ["%4d","M"],\ + ["%4e","N"],\ + ["%4f","O"],\ + ["%50","P"],\ + ["%51","Q"],\ + ["%52","R"],\ + ["%53","S"],\ + ["%54","T"],\ + ["%55","U"],\ + ["%56","V"],\ + ["%57","W"],\ + ["%58","X"],\ + ["%59","Y"],\ + ["%5a","Z"],\ + ["%5b","["],\ + ["%5c","\"],\ + ["%5d","]"],\ + ["%5e","^"],\ + ["%5f","_"],\ + ["%60","`"],\ + ["%61","a"],\ + ["%62","b"],\ + ["%63","c"],\ + ["%64","d"],\ + ["%65","e"],\ + ["%66","f"],\ + ["%67","g"],\ + ["%68","h"],\ + ["%69","i"],\ + ["%6a","j"],\ + ["%6b","k"],\ + ["%6c","l"],\ + ["%6d","m"],\ + ["%6e","n"],\ + ["%6f","o"],\ + ["%70","p"],\ + ["%71","q"],\ + ["%72","r"],\ + ["%73","s"],\ + ["%74","t"],\ + ["%75","u"],\ + ["%76","v"],\ + ["%77","w"],\ + ["%78","x"],\ + ["%79","y"],\ + ["%7a","z"],\ + ["%7b","{"],\ + ["%7c","|"],\ + ["%7d","}"],\ + ["%7e","~"],\ + ["%e2%82%ac","`"],\ + ["%e2%80%9a","‚"],\ + ["%c6%92","ƒ"],\ + ["%e2%80%9e","„"],\ + ["%e2%80%a6","…"],\ + ["%e2%80%a0","†"],\ + ["%e2%80%a1","‡"],\ + ["%cb%86","ˆ"],\ + ["%e2%80%b0","‰"],\ + ["%c5%a0","Š"],\ + ["%e2%80%b9","‹"],\ + ["%c5%92","Œ"],\ + ["%c5%bd","Ž"],\ + ["%e2%80%98","‘"],\ + ["%e2%80%99","’"],\ + ["%e2%80%9c","“"],\ + ["%e2%80%9d","”"],\ + ["%e2%80%a2","•"],\ + ["%e2%80%93","–"],\ + ["%e2%80%94","—"],\ + ["%cb%9c","˜"],\ + ["%e2%84","™"],\ + ["%c5%a1","š"],\ + ["%e2%80","›"],\ + ["%c5%93","œ"],\ + ["%c5%be","ž"],\ + ["%c5%b8","Ÿ"],\ + ["%c2%a1","¡"],\ + ["%c2%a2","¢"],\ + ["%c2%a3","£"],\ + ["%c2%a4","¤"],\ + ["%c2%a5","¥"],\ + ["%c2%a6","¦"],\ + ["%c2%a7","§"],\ + ["%c2%a8","¨"],\ + ["%c2%a9","©"],\ + ["%c2%aa","ª"],\ + ["%c2%ab","«"],\ + ["%c2%ac","¬"],\ + ["%c2%ae","®"],\ + ["%c2%af","¯"],\ + ["%c2%b0","°"],\ + ["%c2%b1","±"],\ + ["%c2%b2","²"],\ + ["%c2%b3","³"],\ + ["%c2%b4","´"],\ + ["%c2%b5","µ"],\ + ["%c2%b6","¶"],\ + ["%c2%b7","·"],\ + ["%c2%b8","¸"],\ + ["%c2%b9","¹"],\ + ["%c2%ba","º"],\ + ["%c2%bb","»"],\ + ["%c2%bc","¼"],\ + ["%c2%bd","½"],\ + ["%c2%be","¾"],\ + ["%c2%bf","¿"],\ + ["%c3%80","À"],\ + ["%c3%81","Á"],\ + ["%c3%82","Â"],\ + ["%c3%83","Ã"],\ + ["%c3%84","Ä"],\ + ["%c3%85","Å"],\ + ["%c3%86","Æ"],\ + ["%c3%87","Ç"],\ + ["%c3%88","È"],\ + ["%c3%89","É"],\ + ["%c3%8a","Ê"],\ + ["%c3%8b","Ë"],\ + ["%c3%8c","Ì"],\ + ["%c3%8d","Í"],\ + ["%c3%8e","Î"],\ + ["%c3%8f","Ï"],\ + ["%c3%90","Ð"],\ + ["%c3%91","Ñ"],\ + ["%c3%92","Ò"],\ + ["%c3%93","Ó"],\ + ["%c3%94","Ô"],\ + ["%c3%95","Õ"],\ + ["%c3%96","Ö"],\ + ["%c3%97","×"],\ + ["%c3%98","Ø"],\ + ["%c3%99","Ù"],\ + ["%c3%9a","Ú"],\ + ["%c3%9b","Û"],\ + ["%c3%9c","Ü"],\ + ["%c3%9d","Ý"],\ + ["%c3%9e","Þ"],\ + ["%c3%9f","ß"],\ + ["%c3%a0","à"],\ + ["%c3%a1","á"],\ + ["%c3%a2","â"],\ + ["%c3%a3","ã"],\ + ["%c3%a4","ä"],\ + ["%c3%a5","å"],\ + ["%c3%a6","æ"],\ + ["%c3%a7","ç"],\ + ["%c3%a8","è"],\ + ["%c3%a9","é"],\ + ["%c3%aa","ê"],\ + ["%c3%ab","ë"],\ + ["%c3%ac","ì"],\ + ["%c3%ad","í"],\ + ["%c3%ae","î"],\ + ["%c3%af","ï"],\ + ["%c3%b0","ð"],\ + ["%c3%b1","ñ"],\ + ["%c3%b2","ò"],\ + ["%c3%b3","ó"],\ + ["%c3%b4","ô"],\ + ["%c3%b5","õ"],\ + ["%c3%b6","ö"],\ + ["%c3%b7","÷"],\ + ["%c3%b8","ø"],\ + ["%c3%b9","ù"],\ + ["%c3%ba","ú"],\ + ["%c3%bb","û"],\ + ["%c3%bc","ü"],\ + ["%c3%bd","ý"],\ + ["%c3%be","þ"],\ + ["%c3%bf","ÿ"],\ + ["%%","%"],\ + ["%25","%"]\ +] diff --git a/addons/ui/fnc_initDisplayDiary.sqf b/addons/ui/fnc_initDisplayDiary.sqf index 0adb2afce..2854341c7 100644 --- a/addons/ui/fnc_initDisplayDiary.sqf +++ b/addons/ui/fnc_initDisplayDiary.sqf @@ -5,7 +5,7 @@ _this spawn { params ["_display"]; private _missionName = _display displayCtrl IDC_DIARY_MISSION_NAME; - private _text = ctrlText _missionName call CBA_fnc_decodeHTML; + private _text = ctrlText _missionName call CBA_fnc_decodeURL; _missionName ctrlSetText _text; }; }; diff --git a/addons/ui/fnc_initDisplayInterrupt.sqf b/addons/ui/fnc_initDisplayInterrupt.sqf index 47cfc66ec..d39515f1c 100644 --- a/addons/ui/fnc_initDisplayInterrupt.sqf +++ b/addons/ui/fnc_initDisplayInterrupt.sqf @@ -1,5 +1,15 @@ #include "script_component.hpp" +_this spawn { + isNil { + params ["_display"]; + + private _missionName = _display displayCtrl IDC_INT_MISSIONNAME; + private _text = ctrlText _missionName call CBA_fnc_decodeURL; + _missionName ctrlSetText _text; + }; +}; + if (isNil QGVAR(MenuButtons)) exitWith {}; params ["_display"]; diff --git a/addons/ui/fnc_initDisplayMultiplayerSetup.sqf b/addons/ui/fnc_initDisplayMultiplayerSetup.sqf index 13630d27a..90594b66f 100644 --- a/addons/ui/fnc_initDisplayMultiplayerSetup.sqf +++ b/addons/ui/fnc_initDisplayMultiplayerSetup.sqf @@ -43,9 +43,14 @@ private _fnc_update = { _playerList lbSetValue [_playerList lbAdd _text, _value]; }; - // replace %20 with space + // replace URL encoding private _missionName = _display displayCtrl IDC_MPSETUP_NAME; - private _text = ctrlText _missionName call (uiNamespace getVariable "CBA_fnc_decodeHTML"); + + private _text = ctrlText _missionName; + with uiNamespace do { + _text = _text call CBA_fnc_decodeURL; + }; + _missionName ctrlSetText _text; }; diff --git a/addons/ui/fnc_initDisplayRemoteMissions.sqf b/addons/ui/fnc_initDisplayRemoteMissions.sqf index d9fbe9389..b4aec7274 100644 --- a/addons/ui/fnc_initDisplayRemoteMissions.sqf +++ b/addons/ui/fnc_initDisplayRemoteMissions.sqf @@ -89,10 +89,12 @@ private _fnc_storeMapMissions = {_this spawn {isNil { // delay a frame private _ctrlMissions = _display displayCtrl IDC_SERVER_MISSION; private _missions = []; - private _fnc_decode = uiNamespace getVariable "CBA_fnc_decodeHTML"; - for "_i" from 0 to (lbSize _ctrlMissions - 1) do { - private _name = (_ctrlMissions lbText _i) call _fnc_decode; + private _name = _ctrlMissions lbText _i; + with uiNamespace do { + _name = _name call CBA_fnc_decodeURL; + }; + private _value = _ctrlMissions lbValue _i; private _data = _ctrlMissions lbData _i; private _color = _ctrlMissions lbColor _i;