Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace more %xy in mission names #1166

Merged
merged 3 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/strings/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CfgFunctions {
PATHTO_FNC(strLen);
PATHTO_FNC(trim);
PATHTO_FNC(sanitizeHTML);
PATHTO_FNC(decodeHTML);
PATHTO_FNC(decodeURL);
};
};
};
Original file line number Diff line number Diff line change
@@ -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>
_string - URL encoded text <STRING>

Returns:
_return - Human readable text <STRING>

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 {
Expand All @@ -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];
Expand Down
219 changes: 219 additions & 0 deletions addons/strings/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,222 @@
#endif

#include "\x\cba\addons\main\script_macros.hpp"

#define UTF8_TABLE [\
["%21","!"],\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just ascii keycodes
https://community.bistudio.com/wiki/toString

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have any good way to translate i.e. %e2%80%98" using toString?

Copy link
Contributor Author

@commy2 commy2 Jun 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this:

missionName
// "%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"

missionName call CBA_fnc_decodeURL
// "¬®¯°±²³´µ¶·¸¹º»¼½¾¿"

toString (missionName splitString "%" apply {call compile format ["0x%1", _x]} apply { _x})
// "¬®¯°±²³´µ¶·¸¹º»¼½¾¿"

So it is not exactly the same as ASCII codes. It seems to follow the UTF-8 conversion table instead:
https://www.w3schools.com/tags/ref_urlencode.asp
Except that % is encoded as %% and not %25.

["%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","%"]\
]
2 changes: 1 addition & 1 deletion addons/ui/fnc_initDisplayDiary.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
10 changes: 10 additions & 0 deletions addons/ui/fnc_initDisplayInterrupt.sqf
Original file line number Diff line number Diff line change
@@ -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"];
Expand Down
9 changes: 7 additions & 2 deletions addons/ui/fnc_initDisplayMultiplayerSetup.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
8 changes: 5 additions & 3 deletions addons/ui/fnc_initDisplayRemoteMissions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down