Fullwidth/halfwidth characters convert-html encode/decode

Discuss and announce AkelPad plugins
Post Reply
  • Author
  • Message
Offline
Posts: 17
Joined: Tue Jul 05, 2011 2:35 am

Fullwidth/halfwidth characters convert-html encode/decode

Post 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")
	}
  
}
Last edited by shoshinsha on Thu Apr 18, 2013 3:30 pm, edited 8 times in total.

DV
Offline
Posts: 1250
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

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

Post 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.

Offline
Posts: 2247
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post 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.

Offline
Posts: 17
Joined: Tue Jul 05, 2011 2:35 am

Post by shoshinsha »

Thank you!
I will correct them soon.

Offline
Posts: 17
Joined: Tue Jul 05, 2011 2:35 am

Post by shoshinsha »

Updated! :D

Offline
Posts: 2247
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

shoshinsha
You miss

Code: Select all

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

Code: Select all

pd->dwSupport |= PDS_NOANSI|PDS_NOAUTOLOAD;

Offline
Posts: 17
Joined: Tue Jul 05, 2011 2:35 am

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

Post 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:

Offline
Site Admin
Posts: 6311
Joined: Thu Jul 06, 2006 7:20 am

Post 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())".

Offline
Posts: 17
Joined: Tue Jul 05, 2011 2:35 am

Post 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!

Offline
Posts: 17
Joined: Tue Jul 05, 2011 2:35 am

Post by shoshinsha »

update for akelpad 4.7

Offline
Posts: 17
Joined: Tue Jul 05, 2011 2:35 am

Post by shoshinsha »

updated!

Offline
Posts: 1
Joined: Fri Mar 24, 2017 7:23 am

Post 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.
Post Reply