한국세무사회 자격시험 사이트

전산세무회계 2013.04.27 12:49
http://license.kacpta.or.kr/

 

Trackbacks 0 : Comments 0

How to detect UTF-8

tip 2013.04.27 12:49

A. case 1

 

[출처] http://stackoverflow.com/questions/1031645/how-to-detect-utf-8-in-plain-c

 

 

_Bool is_utf8(const char * string)
{
   
if(!string) return 0;

   
const unsigned char * bytes = (const unsigned char *)string;
   
while(*bytes)
   
{
       
if( (// ASCII
            
// use bytes[0] <= 0x7F to allow ASCII control characters
                bytes
[0] == 0x09 ||
                bytes
[0] == 0x0A ||
                bytes
[0] == 0x0D ||
               
(0x20 <= bytes[0] && bytes[0] <= 0x7E)
           
)
       
) {
            bytes
+= 1;
           
continue;
       
}

       
if( (// non-overlong 2-byte
               
(0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
               
(0x80 <= bytes[1] && bytes[1] <= 0xBF)
           
)
       
) {
            bytes
+= 2;
           
continue;
       
}

       
if( (// excluding overlongs
                bytes
[0] == 0xE0 &&
               
(0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
               
(0x80 <= bytes[2] && bytes[2] <= 0xBF)
           
) ||
           
(// straight 3-byte
               
((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
                    bytes
[0] == 0xEE ||
                    bytes
[0] == 0xEF) &&
               
(0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
               
(0x80 <= bytes[2] && bytes[2] <= 0xBF)
           
) ||
           
(// excluding surrogates
                bytes
[0] == 0xED &&
               
(0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
               
(0x80 <= bytes[2] && bytes[2] <= 0xBF)
           
)
       
) {
            bytes
+= 3;
           
continue;
       
}

       
if( (// planes 1-3
                bytes
[0] == 0xF0 &&
               
(0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
               
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
               
(0x80 <= bytes[3] && bytes[3] <= 0xBF)
           
) ||
           
(// planes 4-15
               
(0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
               
(0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
               
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
               
(0x80 <= bytes[3] && bytes[3] <= 0xBF)
           
) ||
           
(// plane 16
                bytes
[0] == 0xF4 &&
               
(0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
               
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
               
(0x80 <= bytes[3] && bytes[3] <= 0xBF)
           
)
       
) {
            bytes
+= 4;
           
continue;
       
}

       
return 0;
   
}

   
return 1;
} 

 

B. case 2

 

[출처] http://www.devpia.com/Maeul/Contents/Detail.aspx?BoardID=51&MAEULNO=20&no=8619&page=1

 


BOOL IsUTF8Encode(const char * strUrl)
{
    if (NULL == strUrl)
    {
        return FALSE;
    }

    unsigned char * bytes = (unsigned char *)strUrl;
    while(*bytes)
    {
        if (    (//ASCII
            bytes[0] == 0x09 ||
            bytes[0] == 0x0A ||
            bytes[0] == 0x0D ||
            (0x20 <= bytes[0] && bytes[0] <= 0x7E)
            )
            )
        {
            bytes += 1;
            continue;
        }
        if (    (// non-overlong 2-byte
            (0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
            (0x80 <= bytes[1] && bytes[1] <= 0xBF)
            )
            )
        {
            bytes += 2;
            continue;
        }
        if (    (// excluding overlongs
            bytes[0] == 0xE0 &&
            (0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
            (0x80 <= bytes[2] && bytes[2] <= 0xBF)
            )||
            (// straight 3-byte
            ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
            bytes[0] == 0xEE ||
            bytes[0] == 0xEF) &&
            (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
            (0x80 <= bytes[2] && bytes[2] <= 0xBF)
            )||
            (// excluding surrogates
            bytes[0] == 0xED &&
            (0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
            (0x80 <= bytes[2] && bytes[2] <= 0xBF)
            )
            )
        {
            bytes += 3;
            continue;
        }
        if (    (// planes 1-3
            bytes[0] == 0xF0 &&
            (0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
            (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
            (0x80 <= bytes[3] && bytes[3] <= 0xBF)
            )||
            (// planes 4-15
            (0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
            (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
            (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
            (0x80 <= bytes[3] && bytes[3] <= 0xBF)
            )||
            (// planes 16
            bytes[0] == 0xF4 &&
            (0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
            (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
            (0x80 <= bytes[3] && bytes[3] <= 0xBF)
            )

            ){
                bytes += 4;
                continue;
        }
        return FALSE;
    }
    return TRUE;
}

 

 

 

 

'tip' 카테고리의 다른 글

Windows 방화벽 동작을 제어 하는 "netsh 방화벽" 컨텍스트  (0) 2013.04.30
svn store password unencrypted  (0) 2013.04.27
How to detect UTF-8  (0) 2013.04.27
android debug Source not found  (0) 2013.04.27
TileTemplateType  (0) 2013.04.27
Segoe UI Symbols  (0) 2013.04.27
Trackbacks 0 : Comments 0

android debug Source not found

tip 2013.04.27 12:48

[출처] http://android.opensourceror.org/2010/01/18/android-source/

 

Attaching Android platform source in Eclipse

Are you tired of seeing this when you look at your platform JAR in Eclipse?

Dude, where's my source?

Or how about this when you’re debugging?

How am I supposed to debug this?

Android is open source, right? So how do we see the source?

Some background

  • Tip: If you’re just here to get it working and don’t care where it came from, you can skip on a bit.

This article summarizes and augments three other posts that spelled out how to get the source and use it. It is surprisingly difficult to get your hands on the correct version of the source you need for this purpose, so in addition to describing that process I’m providing the end result for your convenience.

My sources

My three source posts are:

Both the posts and the comments were very helpful, but somewhat out of date now. How to put it all together?

Getting the right code

The source is all available, but it’s spread out among several projects which put together constitute the Android Open Source Project. Thus I needed to install the repo tool (as described on the “Get source” page) in order to pull down all of the relevant git repositories. The articles describe getting the latest code – the trick is getting the code specific to the platform version you’re working on; at the time everyone was working with 1.0!

When you sync the Android repos, you’ll see output describing the available branches and tags something like this:

 * [new branch]      cupcake    -> korg/cupcake
 * [new branch]      cupcake-release -> korg/cupcake-release
 * [new branch]      donut      -> korg/donut
 * [new branch]      donut-release -> korg/donut-release
 * [new branch]      eclair     -> korg/eclair
 * [new branch]      master     -> korg/master
 * [new branch]      release-1.0 -> korg/release-1.0
 * [new tag]         android-1.0 -> android-1.0
 * [new tag]         android-1.5 -> android-1.5
 * [new tag]         android-1.5r2 -> android-1.5r2
 * [new tag]         android-1.5r3 -> android-1.5r3
 * [new tag]         android-1.5r4 -> android-1.5r4
 * [new tag]         android-1.6_r1 -> android-1.6_r1
 * [new tag]         android-1.6_r1.1 -> android-1.6_r1.1
 * [new tag]         android-1.6_r1.2 -> android-1.6_r1.2

This list generally contains some other random stuff and varies by project. The tags seem to be logically named and standardized across projects, but I couldn’t find how to get the repo tool to pull source based on a tag (if someone knows, by all means comment below). Repo takes the -b option to specify a branch however, and the cupcake / donut / eclair branches are universal, so those are what I used to make the source archives linked in this article, e.g.:

repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
repo sync

Of course, branches are generally moving targets, so caveat emptor.

Assembling the code as Eclipse expects it

If you follow the above and have a good connection and some patience, you’ll eventually have a directory full of some 2GiB of “stuff,” some of which is the source code you’re looking for. But Eclipse needs just the source, in just the right place. Forster’s post “View Android Source Code in Eclipse” provides a python script for rounding up the source code and creating a nice zip archive out of it, and Burke’s post “Browsing Android Source in Eclipse” describes how to figure out where to put it – in a “sources” directory created underneath the SDK platform directory. Other comments on those posts are helpful for coercing Eclipse to recognize that the source is available.

What you came here for

Without further ado, here’s how you attach source to your platform classes. N.B. all screenshots are from Eclipse 3.5 “Galileo” – other versions may differ significantly.

Download source

Download the zipped source code that I’ve gathered for each platform you are developing for.

Put the source in place

For each platform, create a folder “sources” under that platform (e.g. sdk/platforms/android-1.5/sources) and unzip the source code into it. Then refresh your project (select project and press F5 or right-click and select “Refresh”).

Right click on the project and refresh

Voila, you should see the source!

YES, I SEE the SOURCE!

Getting the debugger on board

I found that even after I’d placed sources in the platform, if I was debugging and ended up deep in the platform (In this case, with an exception), the debugger might not show the code:

Sometimes the debugger still won't show the source

However, it’s fairly straightforward to fix this. Just click on that “Edit Source Lookup Path” button to add a source lookup path. In that dialog leave “Default” selected and click “Add.”

In the following “Add Source” dialog choose “File System Directory” and hit the OK button:

Then choose the source directory where you unzipped the code. The debugger should now show all the code you can debug into.

Source in the debugger... which may or may not help you figure out what went wrong; in this case, a layout error caught at runtime.

A word of caution, though: Eclipse’s debugger seems to think that once you’ve set a source lookup for one project, it’s relevant for all of them. If you’re using different platforms for different projects, you’ll want to change the source it uses. You can do that by right-clicking on the project in the debugger and choosing “Edit Source Lookup” to repeat this process.

Getting back to source lookup in the debugger

Patches welcome

Hopefully this guide makes attaching source easy for you. If the code provided here seems out of sync with the platform when you’re debugging, let me know. If someone knows a better way to pick out the exact code for the different platform versions, comment below. If I’ve slightly (or utterly) misrepresented something, correct me. If you’re just happy to finally see your source, I’d be glad to hear about it!

Both comments and pings are currently closed.  

'tip' 카테고리의 다른 글

svn store password unencrypted  (0) 2013.04.27
How to detect UTF-8  (0) 2013.04.27
android debug Source not found  (0) 2013.04.27
TileTemplateType  (0) 2013.04.27
Segoe UI Symbols  (0) 2013.04.27
[팁] 맥 부트캠프에서 Windows 8 Release Preview & visual studio 12 멈춤 문제 해결  (0) 2013.04.27
Trackbacks 0 : Comments 0