Page 1 of 1

Fullwidth/halfwidth characters convert-html encode/decode

Posted: Tue Jul 05, 2011 4:18 am
by shoshinsha
Now, I'm working in Japanese.
I have searched a convert between halfwidth(katakana/ascii)/fullwidth plugin but no luck. So I decided to learn how to make akelpad plugin and made it myself.
Functions:
Halfwidth Katakana" Call("Convert::FullKataToHalfKata")
"Fullwidth Katakana->Hiragana" Call("Convert::FullKataToHira")
"Halfwidth Katakana->Fullwidth Katakana" Call("Convert::HalfKataToFullKata")
"Halfwidth Katakana->Hiragana" Call("Convert::HalfKataToHira")
"Hiragana->Katakana" Call("Convert::HiraToFullKata")
"Hiragana->Halfwidth Katakana" Call("Convert::HiraToHalfKata")
"ASCII->Fullwidth ASCII" Call("Convert::FullwidthASCII")
"Fullwidth ASCII->ASCII" Call("Convert::HalfwidthASCII")
SEPARATOR(Plus)
"Html encode" Call("Convert::HtmlEncode")
"Html decode" Call("Convert::HtmlDecode")
download(dll & source)

For 4.7.6

Code: Select all

http://www.mediafire.com/?0xay8569eeij7z9

Code: Select all

http://www.mediafire.com/?ti4mw87v4a8jgcc
ps: I'm a beginner and my english is not good. Please, correct me if i'm wrong!

Update 7/7/2011:
-change unicode charaters->\x#### and numbers
-add Japanese messages
-compile with static libs
-macros->functions

@DV,FeyFre: Thanks!
:lol: :lol: :lol: :lol: :lol: :lol: :lol:

Update 2011/12/01
-Akelpad 4.7
-new html encode

Code: Select all

SEPARATOR
"Convert"  Icon("%a\AkelFiles\Plugs\Convert.dll", 0)
{
  "Html"
  {
	"Encode"
		{
		#encode &<>"'
			"Escape" Call("Convert::HtmlEncode")   
			SEPARATOR
		#encode char > 0x7e
			"NonASCII" Call("Convert::HtmlEncode",0,1)
		#encode char > 0x7e using common entities (for char < 0xff)
			"NonASCII To Common Entities" Call("Convert::HtmlEncode",0,1,1)
		#encode char > 0x7e using entities
			"NonASCII To Entities" Call("Convert::HtmlEncode",0,1,2)
		#encode char > 0x7e with &#xxxx; format
			"NonASCII To Decimal" Call("Convert::HtmlEncode",0,1,3)
		#encode char > 0x7e with &#HHHH; format	
			"NonASCII To HEX" Call("Convert::HtmlEncode",0,1,3,1)
		#encode char > 0x7e with &#hhhh; format	
			"NonASCII To hex" Call("Convert::HtmlEncode",0,1,3,2)
			SEPARATOR
			"All" Call("Convert::HtmlEncode",0,1)
			"All To Common Entities" Call("Convert::HtmlEncode",0,2,1)
			"All To Entities" Call("Convert::HtmlEncode",0,2,2)
			"All To Decimal" Call("Convert::HtmlEncode",0,2,3)
			"All To HEX" Call("Convert::HtmlEncode",0,2,3,1)
			"All To hex" Call("Convert::HtmlEncode",0,2,3,2)
		}
	"Encode ignore existed entities"
		{
			"Escape" Call("Convert::HtmlEncode",1)
			SEPARATOR
			"NonASCII" Call("Convert::HtmlEncode",1,1)
			"NonASCII To Common Entities" Call("Convert::HtmlEncode",1,1,1)
			"NonASCII To Entities" Call("Convert::HtmlEncode",1,1,2)
			"NonASCII To Decimal" Call("Convert::HtmlEncode",1,1,3)
			"NonASCII To HEX" Call("Convert::HtmlEncode",1,1,3,1)
			"NonASCII To hex" Call("Convert::HtmlEncode",1,1,3,2)
			SEPARATOR
			"All" Call("Convert::HtmlEncode",1,1)
			"All To Common Entities" Call("Convert::HtmlEncode",1,2,1)
			"All To Entities" Call("Convert::HtmlEncode",1,2,2)
			"All To Decimal" Call("Convert::HtmlEncode",1,2,3)
			"All To HEX" Call("Convert::HtmlEncode",1,2,3,1)
			"All To hex" Call("Convert::HtmlEncode",1,2,3,2)
		}
	SEPARATOR
	"Decode" Call("Convert::HtmlDecode")
	
  }
  SEPARATOR
	"To FullWidth"
	{
		"Ascii" Call("Convert::FullwidthASCII")
		"Kata To Hira" Call("Convert::FullKataToHira")
		"Hira To Kata" Call("Convert::HiraToFullKata")
		"HalfKata To FullKata" Call("Convert::HalfKataToFullKata")
		"HalfKat To Hira" Call("Convert::HalfKataToHira")
		
	}
	"To HalfWidth"
	{
		"Ascii" Call("Convert::HalfwidthASCII")
		"FullKata To HalfKata" Call("Convert::FullKataToHalfKata")
		"Hira To HalfKata" Call("Convert::HiraToHalfKata")
	}
  
}

Re: Fullwidth/halfwidth characters convert-html encode/decod

Posted: Tue Jul 05, 2011 9:54 am
by DV
Looks good - at least, the implementation (omitting the fact that personally I don't know absolutely anything about Japanese :))
Regarding the functions, it's recommended to set pd->nUnload explicitely at the end of the function body, e.g.

Code: Select all

pd->nUnload = UD_NONUNLOAD_NONACTIVE;
or

Code: Select all

pd->nUnload = UD_NONUNLOAD_ACTIVE;
in case of a modeless dialog. Otherwise you may encounter unexpected behaviour and even a crash.
Though I did not find such assignments in the standard Format plugin, and it looks strange to me :) Better ask Instructor about this.

Posted: Tue Jul 05, 2011 10:15 am
by FeyFre
shoshinsha
Good work, although I have no chance to test it, but I believe it works in proper environment.

You made some no very good assumptions in your code, so unfortunately I could not check plugin carefully, so I made some notices for you:
1. Check

Code: Select all

pd->dwSupport & PDS_GETSUPPORT
should be done unconditionally. When this flag is set you must set support flags: i.e

Code: Select all

pd->dwSupport |= PDS_NOANSI|PDS_NOAUTOLOAD;
2. You are using Unicode literal(L-strings) explicitly, so you must use Unicode variants of API calls explicitly too(i.e you must SendMessageW, MessageBoxW, wsprintfW instead of SendMessage, MessageBox, wsprintf etc)
3. You have converted AkelDll.h into unicode(utf8). Unfortunately not all C-compilers support Unicode-encoded sources. MSVC <7.0/7.1 doesn't, so I could not compile it. About source file ConvertDll.c - you saved it in 932 codepage(Shift-JSI).. unfortunately MSVC 9.0 cannot recognize it correctly, but after conversion into utf8 it works.
4. More about Unicode: I'll advice you not to use Unicode symbols in sources directly, because of encoding problems(see 3). It is good idea to use them indirectly by means of \x#### escape sequences - they are portable(\u is not valid sequence), whereas direct symbols in some environments could be displayed incorrectly(for instance: I see them as boxes, because of my system hasn't CJK monospace fonts(Arial Unicde MS has CJK subset but it is not monospace so source is unreadable).
5. You used MSVC 10 (2010) to develop and build plugin. You have linked against shared version of libc library (msvcr100.dll). But you didn't provided us with SxS metadata: embedded manifest or manifest file with SxS dependencies. So plugin does not loads at all. You should create proper manifest or link against static version of libc(or do not use libs at all)
6. I think it is better to define FullKata2FullHira, HiraToFullkata and ___htmlEncode as function not as macros. Variant as function is easier to support, IMHO.

Good luck.

Posted: Wed Jul 06, 2011 7:56 am
by shoshinsha
Thank you!
I will correct them soon.

Posted: Thu Jul 07, 2011 5:20 am
by shoshinsha
Updated! :D

Posted: Thu Jul 07, 2011 7:37 am
by FeyFre
shoshinsha
You miss

Code: Select all

if(pd->dwSupport & PDS_GETSUPPORT)
  return;
after

Code: Select all

pd->dwSupport |= PDS_NOANSI|PDS_NOAUTOLOAD;

Re: Fullwidth/halfwidth characters convert-html encode/decod

Posted: Thu Jul 07, 2011 11:29 am
by shoshinsha
FeyFre wrote:shoshinsha
You miss

Code: Select all

if(pd->dwSupport & PDS_GETSUPPORT)
  return;
after

Code: Select all

pd->dwSupport |= PDS_NOANSI|PDS_NOAUTOLOAD;
fixed :lol:
thanks :roll:

Posted: Thu Jul 07, 2011 1:24 pm
by Instructor
Only I see the very common purposes of "universalchardet/Japanese encoding detect plugin" and "Fullwidth/halfwidth characters convert-html encode/decode" :) ?


"if (strEqual())" can be replaced with "if (!xstrcmpiW())".

Posted: Wed Jul 13, 2011 11:11 am
by shoshinsha
Instructor wrote:Only I see the very common purposes of "universalchardet/Japanese encoding detect plugin" and "Fullwidth/halfwidth characters convert-html encode/decode" :) ?


"if (strEqual())" can be replaced with "if (!xstrcmpiW())".
:D thanks!

Posted: Thu Dec 01, 2011 9:55 am
by shoshinsha
update for akelpad 4.7

Posted: Fri Jun 22, 2012 12:21 am
by shoshinsha
updated!

Posted: Fri Mar 24, 2017 7:26 am
by iG0R
Hi.
Could you be so kind as to update your plugin from 1.7.0.3 architecture to 2.2.0.4?
Best regards.