查看文章
 
RegexKitLite Objective-C 正则表达示
2009年04月08日 星期三 17:03

Adding RegexKitLite to your Project

Note:

The following outlines a typical set of steps that one would perform. This is not the only way, nor the required way to add RegexKitLite to your application. They may not be correct for your project as each project is unique. They are an overview for those unfamiliar with adding additional shared libraries to the list of libraries your application links against.

Outline of Required Steps

The following outlines the steps required to use RegexKitLite in your project.

  • Linking your application to the ICU dynamic shared library.
  • Adding the RegexKitLite.m and RegexKitLite.h files to your project and application target.
  • Import the RegexKitLite.h header.

Adding RegexKitLite using Xcode

Important:
These instructions apply to Xcode versions 2.4.1 and 3.0. Other versions should be similar, but may vary for specific details.

Unfortunately, adding additional dynamic shared libraries that your application links to is not a straightforward process in Xcode, nor is there any recommended standard way. Two options are presented below— the first is the 'easy' way that alters your applications Xcode build settings to pass an additional command line argument directly to the linker. The second option attempts to add the ICU dynamic shared library to the list of resources for your project and configuring your executable to link against the added resource.

The 'easy' way is the recommended way to link against the ICU dynamic shared library.

The Easy Way To Add The ICU Library
  1. First, determine the build settings layer of your project that should have altered linking configuration change applied to. The build settings in Xcode are divided in to layers and each layer inherits the build settings from the layer above it. The top, global layer is Project Settings, followed by Target Settings, and finally the most specific layer Executable Settings. If your project is large enough to have multiple targets and executables, you probably have an idea which layer is appropriate. If you are unsure or unfamiliar with the different layers, Target Settings is recommended.

  2. Select the appropriate layer from the Project menu. If you are unsure, Project Edit Active Target is recommended.

  3. Select Build from the tab near the top of the Target Info window. Find the Other Linker Flags build setting from the many build settings available and edit it. Add -licucore [dash ell icucore as a single word, without spaces]. If there are already other flags present, it is recommended that you add -licucore to the end of the existing flags.

    Important:
    If other linker flags are present, there must be at least one space separating -licucore from the other linker flags. For example, -flag1 -licucore -flag2
    Note:
    The Configuration drop down menu controls which build configuration the changes you make are applied to. All Configurations should be selected if this is the first time your are making these changes.
  4. Follow the Add The RegexKitLite Source Files To Your Project steps below.
The Hard Way To Add The ICU Library
  1. First, add the ICU dynamic shared library to your Xcode project. You may choose to add the library to any group in your project, and which groups are created by default is dependent on the template type you chose when you created your project. For a typical Cocoa application project, a good choice is the Frameworks group. To add the ICU dynamic shared library, control/right-click on the Framework group and choose Add Existing Files…

  2. Next, you will need to choose the ICU dynamic shared library file to add. Exactly which file to choose depends on your project, but a fairly safe choice is to select /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libicucore.dylib. You may have installed your developer tools in a different location than the default /Developer directory, and the Mac OS X SDK version should be the one your project is targeting, typically the latest one available.

  3. Then, in the dialog that follows, make sure that Copy items into… is unselected. Select the targets you will be using RegexKitLite in and then click Add to add the ICU dynamic shared library to your project.

  4. Once the ICU dynamic shared library is added to your project, you will need to add it to the libraries that your executable is linked with. To do so, expand the Targets group, and then expand the executable targets you will be using RegexKitLite in. You will then need to select the libicucore.dylib file that you added in the previous step and drag it in to the Link Binary With Libraries group for each executable target that you will be using RegexKitLite in. The order of the files within the Link Binary With Libraries group is not important, and for a typical Cocoa application the group will contain the Cocoa.framework file.

Add The RegexKitLite Source Files To Your Project
  1. Next, add the RegexKitLite source files to your Xcode project. In the Groups & Files outline view on the left, control/right-click on the group that would like to add the files to, then select Add Existing Files…

    Note:

    You can perform the following steps once for each file (RegexKitLite.h and RegexKitLite.m), or once by selecting both files from the file dialog.

  2. Select the RegexKitLite.h and / or RegexKitLite.m file from the file chooser dialog.

  3. The next dialog will present you with several options. If you have not already copied the RegexKitLite files in to your projects directory, you may want to click on the Copy items into… option. Select the targets that you would like add the RegexKitLite functionality to.

  4. Finally, you will need to include the RegexKitLite.h header file. The best way to do this is very dependent on your project. If your project consists of only half a dozen source files, you can add:

    #import "RegexKitLite.h"

    manually to each source file that makes uses of RegexKitLites features. If your project has grown beyond this, you've probably already organized a common "master" header to include to capture headers that are required by nearly all source files already.

Adding RegexKitLite using the Shell

Using RegexKitLite from the shell is also easy. Again, you need to add the header #import to the appropriate source files. Then, to link to the ICU library, you typically only need to add -licucore, just as you would any other library. Consider the following example:

File name:link_example.m
#import <Foundation/NSObjCRuntime.h> #import <Foundation/NSAutoreleasePool.h> #import "RegexKitLite.h" int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Copyright COPYRIGHT_SIGN APPROXIMATELY_EQUAL_TO 2008 // Copyright \u00a9 \u2245 2008 char *utf8CString = "Copyright \xC2\xA9 \xE2\x89\x85 2008"; NSString *regexString = @"Copyright (.*) (\\d+)"; NSString *subjectString = [NSString stringWithUTF8String:utf8CString]; NSString *matchedString = [subjectString stringByMatching:regexString capture:1]; NSLog(@"subject: \"%@\"", subjectString); NSLog(@"matched: \"%@\"", matchedString); [pool release]; return(0); }

Compiled and run from the shell:

shell% cd examples shell% gcc -g -I.. -o link_example link_example.m ../RegexKitLite.m -framework Foundation -licucore shell% ./link_example 2008-03-14 03:52:51.187 test[15283:807] subject: "Copyright © ≅ 2008" 2008-03-14 03:52:51.269 test[15283:807] matched: "© ≅" shell%



see more .... http://regexkit.sourceforge.net/RegexKitLite/

download RegexKitLite(已测试,可以用于iphone)

download RegexKit.framework



类别:iphone 开发||添加到搜藏 |分享到i贴吧|浏览(2352)|评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
     

   
帮助中心 | 空间客服 | 投诉中心 | 空间协议
©2012 Baidu