diff --git a/.github/integration-tests.json b/.github/integration-tests.json index 6cf5953e..064a3782 100644 --- a/.github/integration-tests.json +++ b/.github/integration-tests.json @@ -39,6 +39,31 @@ "runner": "ubuntu-latest", "test": "integration_test/app_test.dart", "setup": "tool/ci/setup_linux.ps1" + }, + { + "package": "word_segmenter", + "platform": "windows", + "runner": "windows-latest", + "test": "integration_test/app_test.dart" + }, + { + "package": "word_segmenter", + "platform": "macos", + "runner": "macos-latest", + "test": "integration_test/app_test.dart" + }, + { + "package": "word_segmenter", + "platform": "linux", + "runner": "ubuntu-latest", + "test": "integration_test/app_test.dart", + "setup": "tool/ci/setup_linux.ps1" + }, + { + "package": "word_segmenter", + "platform": "web", + "runner": "ubuntu-latest", + "test": "test/browser" } ] } diff --git a/README.md b/README.md index 92e9bf4b..de363035 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Any questions join the [Mixin Flutter group][mixin_group_url] | [mixin_logger](./packages/mixin_logger) | [![pub package][mixin_logger_version]][mixin_logger_pub] | [![likes][mixin_logger_likes]][mixin_logger_score] | All Platforms | | [mixin_markdown_widget](./packages/mixin_markdown_widget) | [![pub package][mixin_markdown_widget_version]][mixin_markdown_widget_pub] | [![likes][mixin_markdown_widget_likes]][mixin_markdown_widget_score] | Windows, Linux, macOS | | [ui_device](./packages/ui_device) | [![pub package][ui_device_version]][ui_device_pub] | [![likes][ui_device_likes]][ui_device_score] | iOS | -| [string_tokenizer](./packages/string_tokenizer) | Not Published | Not Published | macOS, iOS | +| [word_segmenter](./packages/word_segmenter) | Not Published | Not Published | Windows, Linux, macOS, iOS, Android, web | [desktop_drop_version]: https://img.shields.io/pub/v/desktop_drop.svg diff --git a/packages/string_tokenizer/README.md b/packages/string_tokenizer/README.md deleted file mode 100644 index 948fbbb7..00000000 --- a/packages/string_tokenizer/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# string_tokenizer - -A Flutter package that provides a utility method for breaking text into individual words. - -## Usage - -To use this package, add `string_tokenizer` as -a [dependency in your pubspec.yaml file](https://flutter.dev/docs/development/packages-and-plugins/using-packages). - -```yaml -dependencies: - string_tokenizer: - git: - url: https://github.com/MixinNetwork/flutter-plugins.git - path: packages/string_tokenizer -``` - -Then import the package: - -```dart -import 'package:string_tokenizer/string_tokenizer.dart'; -``` - -### Breaking Text Into Words - -`string_tokenizer` provides a single method `tokenize` which takes a string and breaks it into individual words. - -```dart - -List words = tokenize('This is a sentence.'); -``` - -The `words` list will contain the following strings: - -```log -['This', 'is', 'a', 'sentence'] -``` diff --git a/packages/string_tokenizer/example/.metadata b/packages/string_tokenizer/example/.metadata deleted file mode 100644 index 90eabcff..00000000 --- a/packages/string_tokenizer/example/.metadata +++ /dev/null @@ -1,45 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: "80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819" - channel: "stable" - -project_type: app - -# Tracks metadata for the flutter migrate command -migration: - platforms: - - platform: root - create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - - platform: android - create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - - platform: ios - create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - - platform: linux - create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - - platform: macos - create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - - platform: web - create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - - platform: windows - create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 - - # User provided section - - # List of Local paths (relative to this file) that should be - # ignored by the migrate tool. - # - # Files that are not part of the templates will be ignored by default. - unmanaged_files: - - 'lib/main.dart' - - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/string_tokenizer/example/README.md b/packages/string_tokenizer/example/README.md deleted file mode 100644 index 836aa81f..00000000 --- a/packages/string_tokenizer/example/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# ui_device_example - -Demonstrates how to use the ui_device plugin. - -## Getting Started - -This project is a starting point for a Flutter application. - -A few resources to get you started if this is your first Flutter project: - -- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) -- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) - -For help getting started with Flutter development, view the -[online documentation](https://docs.flutter.dev/), which offers tutorials, -samples, guidance on mobile development, and a full API reference. diff --git a/packages/string_tokenizer/example/ios/Flutter/Debug.xcconfig b/packages/string_tokenizer/example/ios/Flutter/Debug.xcconfig deleted file mode 100644 index ec97fc6f..00000000 --- a/packages/string_tokenizer/example/ios/Flutter/Debug.xcconfig +++ /dev/null @@ -1,2 +0,0 @@ -#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" -#include "Generated.xcconfig" diff --git a/packages/string_tokenizer/example/ios/Flutter/Release.xcconfig b/packages/string_tokenizer/example/ios/Flutter/Release.xcconfig deleted file mode 100644 index c4855bfe..00000000 --- a/packages/string_tokenizer/example/ios/Flutter/Release.xcconfig +++ /dev/null @@ -1,2 +0,0 @@ -#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" -#include "Generated.xcconfig" diff --git a/packages/string_tokenizer/example/ios/Podfile b/packages/string_tokenizer/example/ios/Podfile deleted file mode 100644 index d97f17e2..00000000 --- a/packages/string_tokenizer/example/ios/Podfile +++ /dev/null @@ -1,44 +0,0 @@ -# Uncomment this line to define a global platform for your project -# platform :ios, '12.0' - -# CocoaPods analytics sends network stats synchronously affecting flutter build latency. -ENV['COCOAPODS_DISABLE_STATS'] = 'true' - -project 'Runner', { - 'Debug' => :debug, - 'Profile' => :release, - 'Release' => :release, -} - -def flutter_root - generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) - unless File.exist?(generated_xcode_build_settings_path) - raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" - end - - File.foreach(generated_xcode_build_settings_path) do |line| - matches = line.match(/FLUTTER_ROOT\=(.*)/) - return matches[1].strip if matches - end - raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" -end - -require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) - -flutter_ios_podfile_setup - -target 'Runner' do - use_frameworks! - use_modular_headers! - - flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) - target 'RunnerTests' do - inherit! :search_paths - end -end - -post_install do |installer| - installer.pods_project.targets.each do |target| - flutter_additional_ios_build_settings(target) - end -end diff --git a/packages/string_tokenizer/example/lib/main.dart b/packages/string_tokenizer/example/lib/main.dart deleted file mode 100644 index 70fc9577..00000000 --- a/packages/string_tokenizer/example/lib/main.dart +++ /dev/null @@ -1,100 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:string_tokenizer/string_tokenizer.dart'; - -void main() { - runApp( - MaterialApp( - theme: ThemeData(useMaterial3: true), - home: const HomePage(), - ), - ); -} - -class HomePage extends StatefulWidget { - const HomePage({super.key}); - - @override - State createState() => _HomePageState(); -} - -class _HomePageState extends State { - final _controller = TextEditingController(); - final _outputs = []; - - final _options = [TokenizerUnit.word]; - - @override - void initState() { - super.initState(); - _controller.text = '北京欢迎你'; - } - - @override - Widget build(BuildContext context) { - const spacerSmall = SizedBox(height: 10); - return Scaffold( - appBar: AppBar( - title: const Text('String Tokenizer'), - ), - body: SingleChildScrollView( - child: Container( - padding: const EdgeInsets.all(10), - child: Column( - children: [ - TextField( - controller: _controller, - maxLines: 7, - ), - spacerSmall, - Wrap( - runSpacing: 4, - spacing: 4, - children: [ - for (final unit in TokenizerUnit.values) - Padding( - padding: const EdgeInsets.all(4.0), - child: ChoiceChip( - label: Text(unit.name), - selected: _options.contains(unit), - onSelected: (selected) { - setState(() { - if (selected) { - _options.add(unit); - } else { - _options.remove(unit); - } - }); - }, - ), - ), - ], - ), - spacerSmall, - TextButton( - onPressed: () { - final tokens = tokenize( - _controller.text, - options: _options, - ); - debugPrint('tokens: $tokens'); - setState(() { - _outputs.clear(); - _outputs.addAll(tokens); - }); - }, - child: const Text('tokenizer'), - ), - spacerSmall, - if (_outputs.isNotEmpty) - Wrap( - spacing: 8, - runSpacing: 4, - children: _outputs.map((e) => Text(e)).toList(), - ), - ], - ), - ), - ), - ); - } -} diff --git a/packages/string_tokenizer/example/macos/Flutter/Flutter-Debug.xcconfig b/packages/string_tokenizer/example/macos/Flutter/Flutter-Debug.xcconfig deleted file mode 100644 index 4b81f9b2..00000000 --- a/packages/string_tokenizer/example/macos/Flutter/Flutter-Debug.xcconfig +++ /dev/null @@ -1,2 +0,0 @@ -#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" -#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/packages/string_tokenizer/example/macos/Flutter/Flutter-Release.xcconfig b/packages/string_tokenizer/example/macos/Flutter/Flutter-Release.xcconfig deleted file mode 100644 index 5caa9d15..00000000 --- a/packages/string_tokenizer/example/macos/Flutter/Flutter-Release.xcconfig +++ /dev/null @@ -1,2 +0,0 @@ -#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" -#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/packages/string_tokenizer/example/macos/Podfile b/packages/string_tokenizer/example/macos/Podfile deleted file mode 100644 index c795730d..00000000 --- a/packages/string_tokenizer/example/macos/Podfile +++ /dev/null @@ -1,43 +0,0 @@ -platform :osx, '10.14' - -# CocoaPods analytics sends network stats synchronously affecting flutter build latency. -ENV['COCOAPODS_DISABLE_STATS'] = 'true' - -project 'Runner', { - 'Debug' => :debug, - 'Profile' => :release, - 'Release' => :release, -} - -def flutter_root - generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) - unless File.exist?(generated_xcode_build_settings_path) - raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" - end - - File.foreach(generated_xcode_build_settings_path) do |line| - matches = line.match(/FLUTTER_ROOT\=(.*)/) - return matches[1].strip if matches - end - raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" -end - -require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) - -flutter_macos_podfile_setup - -target 'Runner' do - use_frameworks! - use_modular_headers! - - flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) - target 'RunnerTests' do - inherit! :search_paths - end -end - -post_install do |installer| - installer.pods_project.targets.each do |target| - flutter_additional_macos_build_settings(target) - end -end diff --git a/packages/string_tokenizer/example/macos/Podfile.lock b/packages/string_tokenizer/example/macos/Podfile.lock deleted file mode 100644 index 006d87bd..00000000 --- a/packages/string_tokenizer/example/macos/Podfile.lock +++ /dev/null @@ -1,16 +0,0 @@ -PODS: - - FlutterMacOS (1.0.0) - -DEPENDENCIES: - - FlutterMacOS (from `Flutter/ephemeral`) - -EXTERNAL SOURCES: - FlutterMacOS: - :path: Flutter/ephemeral - -SPEC CHECKSUMS: - FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 - -PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367 - -COCOAPODS: 1.15.2 diff --git a/packages/string_tokenizer/example/pubspec.yaml b/packages/string_tokenizer/example/pubspec.yaml deleted file mode 100644 index 79d3592a..00000000 --- a/packages/string_tokenizer/example/pubspec.yaml +++ /dev/null @@ -1,94 +0,0 @@ -name: string_tokenizer_example -resolution: workspace -description: Demonstrates how to use the string_tokenizer plugin. - -# The following line prevents the package from being accidentally published to -# pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev - -# The following defines the version and build number for your application. -# A version number is three numbers separated by dots, like 1.2.43 -# followed by an optional build number separated by a +. -# Both the version and the builder number may be overridden in flutter -# build by specifying --build-name and --build-number, respectively. -# In Android, build-name is used as versionName while build-number used as versionCode. -# Read more about Android versioning at https://developer.android.com/studio/publish/versioning -# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. -# Read more about iOS versioning at -# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -# In Windows, build-name is used as the major, minor, and patch parts -# of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+1 - -environment: - sdk: ^3.6.0 - -# Dependencies specify other packages that your package needs in order to work. -# To automatically upgrade your package dependencies to the latest versions -# consider running `flutter pub upgrade --major-versions`. Alternatively, -# dependencies can be manually updated by changing the version numbers below to -# the latest version available on pub.dev. To see which dependencies have newer -# versions available, run `flutter pub outdated`. -dependencies: - flutter: - sdk: flutter - - string_tokenizer: - path: ../ - - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.2 - -dev_dependencies: - flutter_test: - sdk: flutter - - # The "flutter_lints" package below contains a set of recommended lints to - # encourage good coding practices. The lint set provided by the package is - # activated in the `analysis_options.yaml` file located at the root of your - # package. See that file for information about deactivating specific lint - # rules and activating additional ones. - flutter_lints: ^6.0.0 - -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter packages. -flutter: - - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. - uses-material-design: true - - # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/assets-and-images/#from-packages - - # To add custom fonts to your application, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/custom-fonts/#from-packages diff --git a/packages/string_tokenizer/ffigen.yaml b/packages/string_tokenizer/ffigen.yaml deleted file mode 100644 index bbc4e676..00000000 --- a/packages/string_tokenizer/ffigen.yaml +++ /dev/null @@ -1,39 +0,0 @@ -# Run with `flutter pub run ffigen --config ffigen.yaml`. -name: CFStringTokenizer -description: | - Bindings for `string_tokenizer`. - - Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`. -output: 'lib/src/string_tokenizer_bindings_generated.dart' -language: objc -exclude-all-by-default: true -objc-interfaces: - include: - - 'CFRange' -enums: - include: - - 'CFStringBuiltInEncodings' - as-int: - include: - - CFStringTokenizerTokenType -unnamed-enums: - include: - - 'kCFStringTokenizer(.*)' -functions: - include: - - 'CFStringCreateWithCString' - - 'CFStringTokenizerCreate' - - 'CFStringTokenizerAdvanceToNextToken' - - 'CFStringTokenizerGetCurrentTokenRange' - - 'CFRelease' -headers: - entry-points: - - '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStringTokenizer.h' - - '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h' - - '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h' - - '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFLocale.h' -preamble: | - // ignore_for_file: camel_case_types, non_constant_identifier_names, unused_element, unused_field, return_of_invalid_type, void_checks, annotate_overrides, no_leading_underscores_for_local_identifiers, library_private_types_in_public_api, constant_identifier_names -comments: - style: any - length: full diff --git a/packages/string_tokenizer/lib/src/string_tokenizer_bindings_generated.dart b/packages/string_tokenizer/lib/src/string_tokenizer_bindings_generated.dart deleted file mode 100644 index b239a636..00000000 --- a/packages/string_tokenizer/lib/src/string_tokenizer_bindings_generated.dart +++ /dev/null @@ -1,268 +0,0 @@ -// ignore_for_file: camel_case_types, non_constant_identifier_names, unused_element, unused_field, return_of_invalid_type, void_checks, annotate_overrides, no_leading_underscores_for_local_identifiers, library_private_types_in_public_api, constant_identifier_names - -// AUTO GENERATED FILE, DO NOT EDIT. -// -// Generated by `package:ffigen`. -// ignore_for_file: type=lint -import 'dart:ffi' as ffi; - -/// Bindings for `string_tokenizer`. -/// -/// Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`. -/// -class CFStringTokenizer { - /// Holds the symbol lookup function. - final ffi.Pointer Function(String symbolName) - _lookup; - - /// The symbols are looked up in [dynamicLibrary]. - CFStringTokenizer(ffi.DynamicLibrary dynamicLibrary) - : _lookup = dynamicLibrary.lookup; - - /// The symbols are looked up with [lookup]. - CFStringTokenizer.fromLookup( - ffi.Pointer Function(String symbolName) - lookup) - : _lookup = lookup; - - void CFRelease( - ffi.Pointer cf, - ) { - return _CFRelease( - cf, - ); - } - - late final _CFReleasePtr = - _lookup)>>( - 'CFRelease'); - late final _CFRelease = - _CFReleasePtr.asFunction)>(); - - ffi.Pointer<__CFString> CFStringCreateWithCString( - ffi.Pointer<__CFAllocator> alloc, - ffi.Pointer cStr, - int encoding, - ) { - return _CFStringCreateWithCString( - alloc, - cStr, - encoding, - ); - } - - late final _CFStringCreateWithCStringPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer<__CFString> Function( - ffi.Pointer<__CFAllocator>, - ffi.Pointer, - ffi.UnsignedInt)>>('CFStringCreateWithCString'); - late final _CFStringCreateWithCString = - _CFStringCreateWithCStringPtr.asFunction< - ffi.Pointer<__CFString> Function( - ffi.Pointer<__CFAllocator>, ffi.Pointer, int)>(); - - /// ! - /// @function CFStringTokenizerCreate - /// @abstract Creates a tokenizer instance. - /// @param alloc The CFAllocator which should be used to allocate memory for the - /// tokenizer and its storage for values. This parameter may be NULL in which - /// case the current default CFAllocator is used. - /// @param string The string to tokenize. - /// @param range The range of characters within the string to be tokenized. The - /// specified range must not exceed the length of the string. - /// @param options Use one of the Tokenization Unit options to specify how the - /// string should be tokenized. Optionally specify one or more attribute - /// specifiers to tell the tokenizer to prepare specified attributes when it - /// tokenizes the string. - /// @param locale The locale to specify language or region specific behavior. Pass - /// NULL if you want tokenizer to identify the locale automatically. - /// @result A reference to the new CFStringTokenizer. - ffi.Pointer<__CFStringTokenizer> CFStringTokenizerCreate( - ffi.Pointer<__CFAllocator> alloc, - ffi.Pointer<__CFString> string, - CFRange range, - int options, - ffi.Pointer<__CFLocale> locale, - ) { - return _CFStringTokenizerCreate( - alloc, - string, - range, - options, - locale, - ); - } - - late final _CFStringTokenizerCreatePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer<__CFStringTokenizer> Function( - ffi.Pointer<__CFAllocator>, - ffi.Pointer<__CFString>, - CFRange, - ffi.UnsignedLong, - ffi.Pointer<__CFLocale>)>>('CFStringTokenizerCreate'); - late final _CFStringTokenizerCreate = _CFStringTokenizerCreatePtr.asFunction< - ffi.Pointer<__CFStringTokenizer> Function(ffi.Pointer<__CFAllocator>, - ffi.Pointer<__CFString>, CFRange, int, ffi.Pointer<__CFLocale>)>(); - - /// ! - /// @function CFStringTokenizerAdvanceToNextToken - /// @abstract Token enumerator. - /// @param tokenizer The reference to CFStringTokenizer returned by - /// CFStringTokenizerCreate. - /// @result Type of the token if succeeded in finding a token and setting it as - /// current token. kCFStringTokenizerTokenNone if failed in finding a token. - /// @discussion If there is no preceding call to CFStringTokenizerGoToTokenAtIndex - /// or CFStringTokenizerAdvanceToNextToken, it finds the first token in the range - /// specified to CFStringTokenizerCreate. If there is a current token after successful - /// call to CFStringTokenizerGoToTokenAtIndex or CFStringTokenizerAdvanceToNextToken, - /// it proceeds to the next token. If succeeded in finding a token, set it as current - /// token and return its token type. Otherwise invalidate current token and return - /// kCFStringTokenizerTokenNone. - /// The range and attribute of the token can be obtained by calling - /// CFStringTokenizerGetCurrentTokenRange and - /// CFStringTokenizerCopyCurrentTokenAttribute. If the token is a compound - /// (with type kCFStringTokenizerTokenHasSubTokensMask or - /// kCFStringTokenizerTokenHasDerivedSubTokensMask), its subtokens and - /// (or) derived subtokens can be obtained by calling CFStringTokenizerGetCurrentSubTokens. - int CFStringTokenizerAdvanceToNextToken( - ffi.Pointer<__CFStringTokenizer> tokenizer, - ) { - return _CFStringTokenizerAdvanceToNextToken( - tokenizer, - ); - } - - late final _CFStringTokenizerAdvanceToNextTokenPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedLong Function(ffi.Pointer<__CFStringTokenizer>)>>( - 'CFStringTokenizerAdvanceToNextToken'); - late final _CFStringTokenizerAdvanceToNextToken = - _CFStringTokenizerAdvanceToNextTokenPtr.asFunction< - int Function(ffi.Pointer<__CFStringTokenizer>)>(); - - /// ! - /// @function CFStringTokenizerGetCurrentTokenRange - /// @abstract Returns the range of current token. - /// @param tokenizer The reference to CFStringTokenizer returned by - /// CFStringTokenizerCreate. - /// @result Range of current token, or {kCFNotFound,0} if there is no current token. - CFRange CFStringTokenizerGetCurrentTokenRange( - ffi.Pointer<__CFStringTokenizer> tokenizer, - ) { - return _CFStringTokenizerGetCurrentTokenRange( - tokenizer, - ); - } - - late final _CFStringTokenizerGetCurrentTokenRangePtr = _lookup< - ffi - .NativeFunction)>>( - 'CFStringTokenizerGetCurrentTokenRange'); - late final _CFStringTokenizerGetCurrentTokenRange = - _CFStringTokenizerGetCurrentTokenRangePtr.asFunction< - CFRange Function(ffi.Pointer<__CFStringTokenizer>)>(); -} - -enum CFStringBuiltInEncodings { - kCFStringEncodingMacRoman(0), - kCFStringEncodingWindowsLatin1(1280), - kCFStringEncodingISOLatin1(513), - kCFStringEncodingNextStepLatin(2817), - kCFStringEncodingASCII(1536), - kCFStringEncodingUnicode(256), - kCFStringEncodingUTF8(134217984), - kCFStringEncodingNonLossyASCII(3071), - kCFStringEncodingUTF16BE(268435712), - kCFStringEncodingUTF16LE(335544576), - kCFStringEncodingUTF32(201326848), - kCFStringEncodingUTF32BE(402653440), - kCFStringEncodingUTF32LE(469762304); - - static const kCFStringEncodingUTF16 = kCFStringEncodingUnicode; - - final int value; - const CFStringBuiltInEncodings(this.value); - - static CFStringBuiltInEncodings fromValue(int value) => switch (value) { - 0 => kCFStringEncodingMacRoman, - 1280 => kCFStringEncodingWindowsLatin1, - 513 => kCFStringEncodingISOLatin1, - 2817 => kCFStringEncodingNextStepLatin, - 1536 => kCFStringEncodingASCII, - 256 => kCFStringEncodingUnicode, - 134217984 => kCFStringEncodingUTF8, - 3071 => kCFStringEncodingNonLossyASCII, - 268435712 => kCFStringEncodingUTF16BE, - 335544576 => kCFStringEncodingUTF16LE, - 201326848 => kCFStringEncodingUTF32, - 402653440 => kCFStringEncodingUTF32BE, - 469762304 => kCFStringEncodingUTF32LE, - _ => throw ArgumentError( - "Unknown value for CFStringBuiltInEncodings: $value"), - }; - - @override - String toString() { - if (this == kCFStringEncodingUnicode) - return "CFStringBuiltInEncodings.kCFStringEncodingUnicode, CFStringBuiltInEncodings.kCFStringEncodingUTF16"; - return super.toString(); - } -} - -final class __CFString extends ffi.Opaque {} - -final class __CFAllocator extends ffi.Opaque {} - -final class __CFStringTokenizer extends ffi.Opaque {} - -final class CFRange extends ffi.Struct { - @ffi.Long() - external int location; - - @ffi.Long() - external int length; -} - -final class __CFLocale extends ffi.Opaque {} - -/// ! -/// Token type -/// CFStringTokenizerGoToTokenAtIndex / CFStringTokenizerAdvanceToNextToken returns -/// the type of current token. -abstract class CFStringTokenizerTokenType { - /// Have no token. - static const kCFStringTokenizerTokenNone = 0; - - /// Normal token - static const kCFStringTokenizerTokenNormal = 1; - - /// ! - /// Compound token which may contain subtokens but with no derived subtokens. - /// Its subtokens can be obtained by calling CFStringTokenizerGetCurrentSubTokens. - static const kCFStringTokenizerTokenHasSubTokensMask = 2; - - /// ! - /// Compound token which may contain derived subtokens. - /// Its subtokens and derived subtokens can be obtained by calling - /// CFStringTokenizerGetCurrentSubTokens. - static const kCFStringTokenizerTokenHasDerivedSubTokensMask = 4; - static const kCFStringTokenizerTokenHasHasNumbersMask = 8; - static const kCFStringTokenizerTokenHasNonLettersMask = 16; - static const kCFStringTokenizerTokenIsCJWordMask = 32; -} - -const int kCFStringTokenizerUnitWord = 0; - -const int kCFStringTokenizerUnitSentence = 1; - -const int kCFStringTokenizerUnitParagraph = 2; - -const int kCFStringTokenizerUnitLineBreak = 3; - -const int kCFStringTokenizerUnitWordBoundary = 4; - -const int kCFStringTokenizerAttributeLatinTranscription = 65536; - -const int kCFStringTokenizerAttributeLanguage = 131072; diff --git a/packages/string_tokenizer/lib/string_tokenizer.dart b/packages/string_tokenizer/lib/string_tokenizer.dart deleted file mode 100644 index 76c3f937..00000000 --- a/packages/string_tokenizer/lib/string_tokenizer.dart +++ /dev/null @@ -1,88 +0,0 @@ -import 'dart:ffi'; - -import 'package:ffi/ffi.dart'; - -import 'src/string_tokenizer_bindings_generated.dart' as binding; - -final DynamicLibrary _dylib = DynamicLibrary.process(); - -final _bindings = binding.CFStringTokenizer(_dylib); - -/// see https://developer.apple.com/documentation/corefoundation/1588024-tokenization_modifiers?language=objc -enum TokenizerUnit { - word, - sentence, - paragraph, - lineBreak, - wordBoundary, - attributeLatinTranscription, - attributeLanguage, -} - -extension _TokenizerUnitExtension on TokenizerUnit { - int get value { - switch (this) { - case TokenizerUnit.word: - return binding.kCFStringTokenizerUnitWord; - case TokenizerUnit.sentence: - return binding.kCFStringTokenizerUnitSentence; - case TokenizerUnit.paragraph: - return binding.kCFStringTokenizerUnitParagraph; - case TokenizerUnit.lineBreak: - return binding.kCFStringTokenizerUnitLineBreak; - case TokenizerUnit.wordBoundary: - return binding.kCFStringTokenizerUnitWordBoundary; - case TokenizerUnit.attributeLatinTranscription: - return binding.kCFStringTokenizerAttributeLatinTranscription; - case TokenizerUnit.attributeLanguage: - return binding.kCFStringTokenizerAttributeLanguage; - } - } -} - -/// Tokenize a string into a list of tokens. -/// -/// [options] empty meanings [TokenizerUnit.word]. -List tokenize( - String string, { - List options = const [], -}) { - final range = malloc(); - range.ref.location = 0; - range.ref.length = string.length; - - final cfString = _bindings.CFStringCreateWithCString( - nullptr, - string.toNativeUtf8().cast(), - binding.CFStringBuiltInEncodings.kCFStringEncodingUTF8.value, - ); - - int optionsInt = 0; - for (final option in options) { - optionsInt |= option.value; - } - - final tokenizer = _bindings.CFStringTokenizerCreate( - nullptr, - cfString, - range.ref, - optionsInt, - nullptr, - ); - final tokens = []; - while (true) { - final tokenType = _bindings.CFStringTokenizerAdvanceToNextToken(tokenizer); - if (tokenType == 0) { - break; - } - final tokenRange = - _bindings.CFStringTokenizerGetCurrentTokenRange(tokenizer); - final token = string.substring( - tokenRange.location, tokenRange.location + tokenRange.length); - tokens.add(token); - } - _bindings.CFRelease(tokenizer.cast()); - _bindings.CFRelease(cfString.cast()); - malloc.free(range); - return tokens; -} diff --git a/packages/string_tokenizer/pubspec.yaml b/packages/string_tokenizer/pubspec.yaml deleted file mode 100644 index 9b632e11..00000000 --- a/packages/string_tokenizer/pubspec.yaml +++ /dev/null @@ -1,24 +0,0 @@ -name: string_tokenizer -resolution: workspace -description: A Flutter package that provides a utility method for breaking text into individual words. -version: 0.0.1 -homepage: https://github.com/MixinNetwork/flutter-plugins - -environment: - sdk: ^3.5.0 - flutter: ">=3.2.0" - -platforms: - macos: - ios: - -dependencies: - flutter: - sdk: flutter - ffi: ^2.1.0 - -dev_dependencies: - ffigen: ^23.0.0 - flutter_test: - sdk: flutter - flutter_lints: ^6.0.0 diff --git a/packages/string_tokenizer/.gitignore b/packages/word_segmenter/.gitignore similarity index 100% rename from packages/string_tokenizer/.gitignore rename to packages/word_segmenter/.gitignore diff --git a/packages/string_tokenizer/.metadata b/packages/word_segmenter/.metadata similarity index 100% rename from packages/string_tokenizer/.metadata rename to packages/word_segmenter/.metadata diff --git a/packages/string_tokenizer/CHANGELOG.md b/packages/word_segmenter/CHANGELOG.md similarity index 100% rename from packages/string_tokenizer/CHANGELOG.md rename to packages/word_segmenter/CHANGELOG.md diff --git a/packages/string_tokenizer/LICENSE b/packages/word_segmenter/LICENSE similarity index 100% rename from packages/string_tokenizer/LICENSE rename to packages/word_segmenter/LICENSE diff --git a/packages/word_segmenter/README.md b/packages/word_segmenter/README.md new file mode 100644 index 00000000..ae604f7e --- /dev/null +++ b/packages/word_segmenter/README.md @@ -0,0 +1,38 @@ +# word_segmenter + +Splits text at word boundaries with the platform's own text services. + +Flutter's engine bundles ICU without the CJK dictionary, so +`TextPainter.getWordBoundary` treats every Chinese or Japanese character as a +word. This package asks the operating system instead, which segments +`我们今天讨论一下` as `我们 | 今天 | 讨论 | 一下`. + +| Platform | Backend | +| --- | --- | +| macOS, iOS | `CFStringTokenizer` | +| Windows | system `icu.dll` (Windows 10 1903+) | +| Linux | system `libicuuc` | +| Android | system `libicu.so` (API 31+) | +| Web | `Intl.Segmenter` | + +No native code or plugin registration is needed: native platforms call the +system libraries through `dart:ffi`. + +## Usage + +```dart +import 'package:word_segmenter/word_segmenter.dart'; + +const text = 'Hello, 世界和平'; +final ranges = wordBoundaries(text); +// ['Hello', ',', ' ', '世界', '和平'] +print(ranges?.map((range) => range.textInside(text)).toList()); +``` + +Segments are contiguous UTF-16 ranges covering the whole text; whitespace and +punctuation form their own segments. `wordBoundaries` returns `null` when the +platform has no segmenter available (for example Android below API 31), so +callers can fall back to `TextPainter.getWordBoundary`. + +Exact segments come from the platform dictionaries and may differ slightly +between platforms. diff --git a/packages/string_tokenizer/analysis_options.yaml b/packages/word_segmenter/analysis_options.yaml similarity index 100% rename from packages/string_tokenizer/analysis_options.yaml rename to packages/word_segmenter/analysis_options.yaml diff --git a/packages/string_tokenizer/example/.gitignore b/packages/word_segmenter/example/.gitignore similarity index 97% rename from packages/string_tokenizer/example/.gitignore rename to packages/word_segmenter/example/.gitignore index 24476c5d..6c319542 100644 --- a/packages/string_tokenizer/example/.gitignore +++ b/packages/word_segmenter/example/.gitignore @@ -5,9 +5,11 @@ *.swp .DS_Store .atom/ +.build/ .buildlog/ .history .svn/ +.swiftpm/ migrate_working_dir/ # IntelliJ related diff --git a/packages/word_segmenter/example/.metadata b/packages/word_segmenter/example/.metadata new file mode 100644 index 00000000..3602f1dd --- /dev/null +++ b/packages/word_segmenter/example/.metadata @@ -0,0 +1,45 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "abaf9c523780a608bd46686fd5e53740a07077f8" + channel: "stable" + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + base_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + - platform: android + create_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + base_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + - platform: ios + create_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + base_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + - platform: linux + create_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + base_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + - platform: macos + create_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + base_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + - platform: web + create_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + base_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + - platform: windows + create_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + base_revision: abaf9c523780a608bd46686fd5e53740a07077f8 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/word_segmenter/example/README.md b/packages/word_segmenter/example/README.md new file mode 100644 index 00000000..24e300e7 --- /dev/null +++ b/packages/word_segmenter/example/README.md @@ -0,0 +1,8 @@ +# word_segmenter_example + +Type text to see how `wordBoundaries` splits it on the current platform. + +```bash +flutter run -d +flutter test integration_test/app_test.dart -d +``` diff --git a/packages/string_tokenizer/example/analysis_options.yaml b/packages/word_segmenter/example/analysis_options.yaml similarity index 96% rename from packages/string_tokenizer/example/analysis_options.yaml rename to packages/word_segmenter/example/analysis_options.yaml index 4c1260be..d3ccccb8 100644 --- a/packages/string_tokenizer/example/analysis_options.yaml +++ b/packages/word_segmenter/example/analysis_options.yaml @@ -12,6 +12,10 @@ analyzer: - build/** - ios/** - macos/** + - android/** + - web/** + - windows/** + - linux/** include: package:flutter_lints/flutter.yaml linter: diff --git a/packages/word_segmenter/example/android/.gitignore b/packages/word_segmenter/example/android/.gitignore new file mode 100644 index 00000000..be3943c9 --- /dev/null +++ b/packages/word_segmenter/example/android/.gitignore @@ -0,0 +1,14 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java +.cxx/ + +# Remember to never publicly share your keystore. +# See https://flutter.dev/to/reference-keystore +key.properties +**/*.keystore +**/*.jks diff --git a/packages/word_segmenter/example/android/app/build.gradle.kts b/packages/word_segmenter/example/android/app/build.gradle.kts new file mode 100644 index 00000000..9a9aa0d7 --- /dev/null +++ b/packages/word_segmenter/example/android/app/build.gradle.kts @@ -0,0 +1,49 @@ +plugins { + id("com.android.application") + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id("dev.flutter.flutter-gradle-plugin") +} + +android { + namespace = "com.example.word_segmenter_example" + compileSdk = flutter.compileSdkVersion + ndkVersion = flutter.ndkVersion + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId = "com.example.word_segmenter_example" + // You can update the following values to match your application needs. + // For more information, see: https://flutter.dev/to/review-gradle-config. + minSdk = flutter.minSdkVersion + targetSdk = flutter.targetSdkVersion + // Uses the version code from pubspec.yaml. When using split APKs, 1000 * ABI_VERSION + // is added automatically by Flutter. (https://developer.android.com/studio/build/configure-apk-splits#configure-APK-versions) + // You can force using the value of versionCode by specifying the `-P force-version-code-ignoring-abi=true` + // flag during build. + versionCode = flutter.versionCode + versionName = flutter.versionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig = signingConfigs.getByName("debug") + } + } +} + +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } +} + +flutter { + source = "../.." +} diff --git a/packages/word_segmenter/example/android/app/src/debug/AndroidManifest.xml b/packages/word_segmenter/example/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 00000000..399f6981 --- /dev/null +++ b/packages/word_segmenter/example/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/packages/word_segmenter/example/android/app/src/main/AndroidManifest.xml b/packages/word_segmenter/example/android/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..16e357b6 --- /dev/null +++ b/packages/word_segmenter/example/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/word_segmenter/example/android/app/src/main/kotlin/com/example/word_segmenter_example/MainActivity.kt b/packages/word_segmenter/example/android/app/src/main/kotlin/com/example/word_segmenter_example/MainActivity.kt new file mode 100644 index 00000000..eb89c596 --- /dev/null +++ b/packages/word_segmenter/example/android/app/src/main/kotlin/com/example/word_segmenter_example/MainActivity.kt @@ -0,0 +1,5 @@ +package com.example.word_segmenter_example + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity : FlutterActivity() diff --git a/packages/word_segmenter/example/android/app/src/main/res/drawable-v21/launch_background.xml b/packages/word_segmenter/example/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 00000000..f74085f3 --- /dev/null +++ b/packages/word_segmenter/example/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/packages/word_segmenter/example/android/app/src/main/res/drawable/launch_background.xml b/packages/word_segmenter/example/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 00000000..304732f8 --- /dev/null +++ b/packages/word_segmenter/example/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/packages/word_segmenter/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/packages/word_segmenter/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..db77bb4b Binary files /dev/null and b/packages/word_segmenter/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/packages/word_segmenter/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/packages/word_segmenter/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..17987b79 Binary files /dev/null and b/packages/word_segmenter/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/packages/word_segmenter/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/packages/word_segmenter/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..09d43914 Binary files /dev/null and b/packages/word_segmenter/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/packages/word_segmenter/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/packages/word_segmenter/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..d5f1c8d3 Binary files /dev/null and b/packages/word_segmenter/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/packages/word_segmenter/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/packages/word_segmenter/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..4d6372ee Binary files /dev/null and b/packages/word_segmenter/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/packages/word_segmenter/example/android/app/src/main/res/values-night/styles.xml b/packages/word_segmenter/example/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 00000000..06952be7 --- /dev/null +++ b/packages/word_segmenter/example/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/packages/word_segmenter/example/android/app/src/main/res/values/styles.xml b/packages/word_segmenter/example/android/app/src/main/res/values/styles.xml new file mode 100644 index 00000000..cb1ef880 --- /dev/null +++ b/packages/word_segmenter/example/android/app/src/main/res/values/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/packages/word_segmenter/example/android/app/src/profile/AndroidManifest.xml b/packages/word_segmenter/example/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 00000000..399f6981 --- /dev/null +++ b/packages/word_segmenter/example/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/packages/word_segmenter/example/android/build.gradle.kts b/packages/word_segmenter/example/android/build.gradle.kts new file mode 100644 index 00000000..dbee657b --- /dev/null +++ b/packages/word_segmenter/example/android/build.gradle.kts @@ -0,0 +1,24 @@ +allprojects { + repositories { + google() + mavenCentral() + } +} + +val newBuildDir: Directory = + rootProject.layout.buildDirectory + .dir("../../build") + .get() +rootProject.layout.buildDirectory.value(newBuildDir) + +subprojects { + val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name) + project.layout.buildDirectory.value(newSubprojectBuildDir) +} +subprojects { + project.evaluationDependsOn(":app") +} + +tasks.register("clean") { + delete(rootProject.layout.buildDirectory) +} diff --git a/packages/word_segmenter/example/android/gradle.properties b/packages/word_segmenter/example/android/gradle.properties new file mode 100644 index 00000000..e96108cf --- /dev/null +++ b/packages/word_segmenter/example/android/gradle.properties @@ -0,0 +1,6 @@ +org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError +android.useAndroidX=true +# This newDsl flag was added by the Flutter template +android.newDsl=false +# This builtInKotlin flag was added by the Flutter template +android.builtInKotlin=false diff --git a/packages/word_segmenter/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/word_segmenter/example/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..a20f2c46 --- /dev/null +++ b/packages/word_segmenter/example/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-all.zip diff --git a/packages/word_segmenter/example/android/settings.gradle.kts b/packages/word_segmenter/example/android/settings.gradle.kts new file mode 100644 index 00000000..b28021a9 --- /dev/null +++ b/packages/word_segmenter/example/android/settings.gradle.kts @@ -0,0 +1,26 @@ +pluginManagement { + val flutterSdkPath = + run { + val properties = java.util.Properties() + file("local.properties").inputStream().use { properties.load(it) } + val flutterSdkPath = properties.getProperty("flutter.sdk") + require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" } + flutterSdkPath + } + + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") + + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +plugins { + id("dev.flutter.flutter-plugin-loader") version "1.0.0" + id("com.android.application") version "9.1.0" apply false + id("org.jetbrains.kotlin.android") version "2.4.0" apply false +} + +include(":app") diff --git a/packages/word_segmenter/example/integration_test/app_test.dart b/packages/word_segmenter/example/integration_test/app_test.dart new file mode 100644 index 00000000..4dc2f08c --- /dev/null +++ b/packages/word_segmenter/example/integration_test/app_test.dart @@ -0,0 +1,26 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:word_segmenter/word_segmenter.dart'; +import 'package:word_segmenter_example/main.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + test('segments Chinese with the system dictionary', () { + const text = '我们今天讨论一下,Hello world!'; + final segments = [ + for (final range in wordBoundaries(text)!) range.textInside(text), + ]; + expect(segments.join(), text); + expect( + segments, + containsAllInOrder(['我们', '今天', '讨论', ',', 'Hello', ' ', 'world']), + ); + }); + + testWidgets('example shows the segments', (tester) async { + await tester.pumpWidget(const ExampleApp()); + expect(find.text('我们'), findsOneWidget); + expect(find.text('No word segmenter on this platform.'), findsNothing); + }); +} diff --git a/packages/string_tokenizer/example/ios/.gitignore b/packages/word_segmenter/example/ios/.gitignore similarity index 100% rename from packages/string_tokenizer/example/ios/.gitignore rename to packages/word_segmenter/example/ios/.gitignore diff --git a/packages/string_tokenizer/example/ios/Flutter/AppFrameworkInfo.plist b/packages/word_segmenter/example/ios/Flutter/AppFrameworkInfo.plist similarity index 93% rename from packages/string_tokenizer/example/ios/Flutter/AppFrameworkInfo.plist rename to packages/word_segmenter/example/ios/Flutter/AppFrameworkInfo.plist index 9625e105..391a902b 100644 --- a/packages/string_tokenizer/example/ios/Flutter/AppFrameworkInfo.plist +++ b/packages/word_segmenter/example/ios/Flutter/AppFrameworkInfo.plist @@ -20,7 +20,5 @@ ???? CFBundleVersion 1.0 - MinimumOSVersion - 11.0 diff --git a/packages/word_segmenter/example/ios/Flutter/Debug.xcconfig b/packages/word_segmenter/example/ios/Flutter/Debug.xcconfig new file mode 100644 index 00000000..592ceee8 --- /dev/null +++ b/packages/word_segmenter/example/ios/Flutter/Debug.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/packages/word_segmenter/example/ios/Flutter/Release.xcconfig b/packages/word_segmenter/example/ios/Flutter/Release.xcconfig new file mode 100644 index 00000000..592ceee8 --- /dev/null +++ b/packages/word_segmenter/example/ios/Flutter/Release.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/packages/string_tokenizer/example/ios/Runner.xcodeproj/project.pbxproj b/packages/word_segmenter/example/ios/Runner.xcodeproj/project.pbxproj similarity index 70% rename from packages/string_tokenizer/example/ios/Runner.xcodeproj/project.pbxproj rename to packages/word_segmenter/example/ios/Runner.xcodeproj/project.pbxproj index 00e7aa26..2d64339e 100644 --- a/packages/string_tokenizer/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/word_segmenter/example/ios/Runner.xcodeproj/project.pbxproj @@ -8,13 +8,26 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; + 7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */; }; + 78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 331C8085294A63A400263BE5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 97C146E61CF9000F007C117D /* Project object */; + proxyType = 1; + remoteGlobalIDString = 97C146ED1CF9000F007C117D; + remoteInfo = Runner; + }; +/* End PBXContainerItemProxy section */ + /* Begin PBXCopyFilesBuildPhase section */ 9705A1C41CF9048500538489 /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; @@ -31,9 +44,13 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = ""; }; + 331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterGeneratedPluginSwiftPackage; path = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; @@ -49,15 +66,25 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 331C8082294A63A400263BE5 /* RunnerTests */ = { + isa = PBXGroup; + children = ( + 331C807B294A618700263BE5 /* RunnerTests.swift */, + ); + path = RunnerTests; + sourceTree = ""; + }; 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( + 78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 9740EEB21CF90195004384FC /* Debug.xcconfig */, 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, @@ -72,6 +99,7 @@ 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, + 331C8082294A63A400263BE5 /* RunnerTests */, ); sourceTree = ""; }; @@ -79,6 +107,7 @@ isa = PBXGroup; children = ( 97C146EE1CF9000F007C117D /* Runner.app */, + 331C8081294A63A400263BE5 /* RunnerTests.xctest */, ); name = Products; sourceTree = ""; @@ -93,6 +122,7 @@ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, + 7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */, 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, ); path = Runner; @@ -101,6 +131,23 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 331C8080294A63A400263BE5 /* RunnerTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */; + buildPhases = ( + 331C807D294A63A400263BE5 /* Sources */, + 331C807F294A63A400263BE5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 331C8086294A63A400263BE5 /* PBXTargetDependency */, + ); + name = RunnerTests; + productName = RunnerTests; + productReference = 331C8081294A63A400263BE5 /* RunnerTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; 97C146ED1CF9000F007C117D /* Runner */ = { isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; @@ -117,6 +164,9 @@ dependencies = ( ); name = Runner; + packageProductDependencies = ( + 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */, + ); productName = Runner; productReference = 97C146EE1CF9000F007C117D /* Runner.app */; productType = "com.apple.product-type.application"; @@ -127,9 +177,14 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + BuildIndependentTargetsInParallel = YES; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { + 331C8080294A63A400263BE5 = { + CreatedOnToolsVersion = 14.0; + TestTargetID = 97C146ED1CF9000F007C117D; + }; 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; LastSwiftMigration = 1100; @@ -145,16 +200,27 @@ Base, ); mainGroup = 97C146E51CF9000F007C117D; + packageReferences = ( + 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */, + ); productRefGroup = 97C146EF1CF9000F007C117D /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( 97C146ED1CF9000F007C117D /* Runner */, + 331C8080294A63A400263BE5 /* RunnerTests */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 331C807F294A63A400263BE5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 97C146EC1CF9000F007C117D /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -176,6 +242,7 @@ files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( @@ -202,17 +269,34 @@ /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 331C807D294A63A400263BE5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 97C146EA1CF9000F007C117D /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, + 7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 331C8086294A63A400263BE5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 97C146ED1CF9000F007C117D /* Runner */; + targetProxy = 331C8085294A63A400263BE5 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ 97C146FA1CF9000F007C117D /* Main.storyboard */ = { isa = PBXVariantGroup; @@ -237,6 +321,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; @@ -266,6 +351,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -274,9 +360,10 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + STRING_CATALOG_GENERATE_SYMBOLS = YES; SUPPORTED_PLATFORMS = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; @@ -297,7 +384,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.example; + PRODUCT_BUNDLE_IDENTIFIER = com.example.wordSegmenterExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -305,10 +392,58 @@ }; name = Profile; }; + 331C8088294A63A400263BE5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.wordSegmenterExample.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Debug; + }; + 331C8089294A63A400263BE5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.wordSegmenterExample.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Release; + }; + 331C808A294A63A400263BE5 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.wordSegmenterExample.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Profile; + }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; @@ -338,6 +473,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -352,10 +488,11 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + STRING_CATALOG_GENERATE_SYMBOLS = YES; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -364,6 +501,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; @@ -393,6 +531,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -401,9 +540,10 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + STRING_CATALOG_GENERATE_SYMBOLS = YES; SUPPORTED_PLATFORMS = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; @@ -426,7 +566,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.example; + PRODUCT_BUNDLE_IDENTIFIER = com.example.wordSegmenterExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -449,7 +589,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.example; + PRODUCT_BUNDLE_IDENTIFIER = com.example.wordSegmenterExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -460,6 +600,16 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 331C8088294A63A400263BE5 /* Debug */, + 331C8089294A63A400263BE5 /* Release */, + 331C808A294A63A400263BE5 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { isa = XCConfigurationList; buildConfigurations = ( @@ -481,6 +631,20 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCLocalSwiftPackageReference section */ + 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */ = { + isa = XCLocalSwiftPackageReference; + relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; + }; +/* End XCLocalSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */ = { + isa = XCSwiftPackageProductDependency; + productName = FlutterGeneratedPluginSwiftPackage; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 97C146E61CF9000F007C117D /* Project object */; } diff --git a/packages/string_tokenizer/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/packages/word_segmenter/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from packages/string_tokenizer/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to packages/word_segmenter/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/packages/string_tokenizer/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/word_segmenter/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from packages/string_tokenizer/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/word_segmenter/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/packages/string_tokenizer/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/packages/word_segmenter/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from packages/string_tokenizer/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to packages/word_segmenter/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/packages/string_tokenizer/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/word_segmenter/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 66% rename from packages/string_tokenizer/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to packages/word_segmenter/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index c87d15a3..c3fedb29 100644 --- a/packages/string_tokenizer/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/word_segmenter/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,10 +1,28 @@ + + + + + + + + + + + + + + diff --git a/packages/string_tokenizer/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/packages/word_segmenter/example/ios/Runner.xcworkspace/contents.xcworkspacedata similarity index 100% rename from packages/string_tokenizer/example/ios/Runner.xcworkspace/contents.xcworkspacedata rename to packages/word_segmenter/example/ios/Runner.xcworkspace/contents.xcworkspacedata diff --git a/packages/string_tokenizer/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/word_segmenter/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from packages/string_tokenizer/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/word_segmenter/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/packages/string_tokenizer/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/packages/word_segmenter/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from packages/string_tokenizer/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to packages/word_segmenter/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/packages/string_tokenizer/example/ios/Runner/AppDelegate.swift b/packages/word_segmenter/example/ios/Runner/AppDelegate.swift similarity index 53% rename from packages/string_tokenizer/example/ios/Runner/AppDelegate.swift rename to packages/word_segmenter/example/ios/Runner/AppDelegate.swift index 70693e4a..c30b367e 100644 --- a/packages/string_tokenizer/example/ios/Runner/AppDelegate.swift +++ b/packages/word_segmenter/example/ios/Runner/AppDelegate.swift @@ -1,13 +1,16 @@ -import UIKit import Flutter +import UIKit -@UIApplicationMain -@objc class AppDelegate: FlutterAppDelegate { +@main +@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { - GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } + + func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) { + GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry) + } } diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png diff --git a/packages/string_tokenizer/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/packages/word_segmenter/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md rename to packages/word_segmenter/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md diff --git a/packages/string_tokenizer/example/ios/Runner/Base.lproj/LaunchScreen.storyboard b/packages/word_segmenter/example/ios/Runner/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Base.lproj/LaunchScreen.storyboard rename to packages/word_segmenter/example/ios/Runner/Base.lproj/LaunchScreen.storyboard diff --git a/packages/string_tokenizer/example/ios/Runner/Base.lproj/Main.storyboard b/packages/word_segmenter/example/ios/Runner/Base.lproj/Main.storyboard similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Base.lproj/Main.storyboard rename to packages/word_segmenter/example/ios/Runner/Base.lproj/Main.storyboard diff --git a/packages/string_tokenizer/example/ios/Runner/Info.plist b/packages/word_segmenter/example/ios/Runner/Info.plist similarity index 70% rename from packages/string_tokenizer/example/ios/Runner/Info.plist rename to packages/word_segmenter/example/ios/Runner/Info.plist index 7f553465..43783f7a 100644 --- a/packages/string_tokenizer/example/ios/Runner/Info.plist +++ b/packages/word_segmenter/example/ios/Runner/Info.plist @@ -2,10 +2,12 @@ + CADisableMinimumFrameDurationOnPhone + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleDisplayName - Example + Word Segmenter Example CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier @@ -13,7 +15,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleName - example + word_segmenter_example CFBundlePackageType APPL CFBundleShortVersionString @@ -24,6 +26,29 @@ $(FLUTTER_BUILD_NUMBER) LSRequiresIPhoneOS + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneClassName + UIWindowScene + UISceneConfigurationName + flutter + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + UIApplicationSupportsIndirectInputEvents + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -41,11 +66,5 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - UIViewControllerBasedStatusBarAppearance - - CADisableMinimumFrameDurationOnPhone - - UIApplicationSupportsIndirectInputEvents - diff --git a/packages/string_tokenizer/example/ios/Runner/Runner-Bridging-Header.h b/packages/word_segmenter/example/ios/Runner/Runner-Bridging-Header.h similarity index 100% rename from packages/string_tokenizer/example/ios/Runner/Runner-Bridging-Header.h rename to packages/word_segmenter/example/ios/Runner/Runner-Bridging-Header.h diff --git a/packages/word_segmenter/example/ios/Runner/SceneDelegate.swift b/packages/word_segmenter/example/ios/Runner/SceneDelegate.swift new file mode 100644 index 00000000..b9ce8ea2 --- /dev/null +++ b/packages/word_segmenter/example/ios/Runner/SceneDelegate.swift @@ -0,0 +1,6 @@ +import Flutter +import UIKit + +class SceneDelegate: FlutterSceneDelegate { + +} diff --git a/packages/string_tokenizer/example/ios/RunnerTests/RunnerTests.swift b/packages/word_segmenter/example/ios/RunnerTests/RunnerTests.swift similarity index 100% rename from packages/string_tokenizer/example/ios/RunnerTests/RunnerTests.swift rename to packages/word_segmenter/example/ios/RunnerTests/RunnerTests.swift diff --git a/packages/word_segmenter/example/lib/main.dart b/packages/word_segmenter/example/lib/main.dart new file mode 100644 index 00000000..27218353 --- /dev/null +++ b/packages/word_segmenter/example/lib/main.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:word_segmenter/word_segmenter.dart'; + +void main() => runApp(const ExampleApp()); + +class ExampleApp extends StatelessWidget { + const ExampleApp({super.key}); + + @override + Widget build(BuildContext context) => MaterialApp( + theme: ThemeData(useMaterial3: true), + home: const HomePage(), + ); +} + +class HomePage extends StatefulWidget { + const HomePage({super.key}); + + @override + State createState() => _HomePageState(); +} + +class _HomePageState extends State { + final _controller = TextEditingController(text: '我们今天讨论一下流式输出的性能问题。'); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final text = _controller.text; + final ranges = wordBoundaries(text); + return Scaffold( + appBar: AppBar(title: const Text('Word Segmenter')), + body: ListView( + padding: const EdgeInsets.all(16), + children: [ + TextField( + controller: _controller, + maxLines: null, + onChanged: (_) => setState(() {}), + ), + const SizedBox(height: 16), + if (ranges == null) + const Text('No word segmenter on this platform.') + else + Wrap( + spacing: 4, + runSpacing: 4, + children: [ + for (final range in ranges) + Chip(label: Text(range.textInside(text))), + ], + ), + ], + ), + ); + } +} diff --git a/packages/word_segmenter/example/linux/.gitignore b/packages/word_segmenter/example/linux/.gitignore new file mode 100644 index 00000000..d3896c98 --- /dev/null +++ b/packages/word_segmenter/example/linux/.gitignore @@ -0,0 +1 @@ +flutter/ephemeral diff --git a/packages/word_segmenter/example/linux/CMakeLists.txt b/packages/word_segmenter/example/linux/CMakeLists.txt new file mode 100644 index 00000000..9de9760b --- /dev/null +++ b/packages/word_segmenter/example/linux/CMakeLists.txt @@ -0,0 +1,128 @@ +# Project-level configuration. +cmake_minimum_required(VERSION 3.13) +project(runner LANGUAGES CXX) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "word_segmenter_example") +# The unique GTK application identifier for this application. See: +# https://wiki.gnome.org/HowDoI/ChooseApplicationID +set(APPLICATION_ID "com.example.word_segmenter_example") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(SET CMP0063 NEW) + +# Load bundled libraries from the lib/ directory relative to the binary. +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Root filesystem for cross-building. +if(FLUTTER_TARGET_PLATFORM_SYSROOT) + set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endif() + +# Define build configuration options. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") +endif() + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_14) + target_compile_options(${TARGET} PRIVATE -Wall -Werror) + target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) + +# Application build; see runner/CMakeLists.txt. +add_subdirectory("runner") + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) + +# Only the install-generated bundle's copy of the executable will launch +# correctly, since the resources must in the right relative locations. To avoid +# people trying to run the unbundled copy, put it in a subdirectory instead of +# the default top-level location. +set_target_properties(${BINARY_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" +) + + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# By default, "installing" just makes a relocatable bundle in the build +# directory. +set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +# Start with a clean build bundle directory every time. +install(CODE " + file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") + " COMPONENT Runtime) + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) + install(FILES "${bundled_library}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endforeach(bundled_library) + +# Copy the native assets provided by the build.dart from all packages. +set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") +install(DIRECTORY "${NATIVE_ASSETS_DIR}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") + install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() diff --git a/packages/word_segmenter/example/linux/flutter/CMakeLists.txt b/packages/word_segmenter/example/linux/flutter/CMakeLists.txt new file mode 100644 index 00000000..d5bd0164 --- /dev/null +++ b/packages/word_segmenter/example/linux/flutter/CMakeLists.txt @@ -0,0 +1,88 @@ +# This file controls Flutter-level build steps. It should not be edited. +cmake_minimum_required(VERSION 3.10) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. + +# Serves the same purpose as list(TRANSFORM ... PREPEND ...), +# which isn't available in 3.10. +function(list_prepend LIST_NAME PREFIX) + set(NEW_LIST "") + foreach(element ${${LIST_NAME}}) + list(APPEND NEW_LIST "${PREFIX}${element}") + endforeach(element) + set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) +endfunction() + +# === Flutter Library === +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) +pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) +pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) + +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "fl_basic_message_channel.h" + "fl_binary_codec.h" + "fl_binary_messenger.h" + "fl_dart_project.h" + "fl_engine.h" + "fl_json_message_codec.h" + "fl_json_method_codec.h" + "fl_message_codec.h" + "fl_method_call.h" + "fl_method_channel.h" + "fl_method_codec.h" + "fl_method_response.h" + "fl_plugin_registrar.h" + "fl_plugin_registry.h" + "fl_standard_message_codec.h" + "fl_standard_method_codec.h" + "fl_string_codec.h" + "fl_value.h" + "fl_view.h" + "flutter_linux.h" +) +list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") +target_link_libraries(flutter INTERFACE + PkgConfig::GTK + PkgConfig::GLIB + PkgConfig::GIO +) +add_dependencies(flutter flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CMAKE_CURRENT_BINARY_DIR}/_phony_ + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" + ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} +) diff --git a/packages/word_segmenter/example/linux/flutter/generated_plugin_registrant.cc b/packages/word_segmenter/example/linux/flutter/generated_plugin_registrant.cc new file mode 100644 index 00000000..e71a16d2 --- /dev/null +++ b/packages/word_segmenter/example/linux/flutter/generated_plugin_registrant.cc @@ -0,0 +1,11 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + + +void fl_register_plugins(FlPluginRegistry* registry) { +} diff --git a/packages/word_segmenter/example/linux/flutter/generated_plugin_registrant.h b/packages/word_segmenter/example/linux/flutter/generated_plugin_registrant.h new file mode 100644 index 00000000..e0f0a47b --- /dev/null +++ b/packages/word_segmenter/example/linux/flutter/generated_plugin_registrant.h @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void fl_register_plugins(FlPluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/packages/word_segmenter/example/linux/flutter/generated_plugins.cmake b/packages/word_segmenter/example/linux/flutter/generated_plugins.cmake new file mode 100644 index 00000000..2e1de87a --- /dev/null +++ b/packages/word_segmenter/example/linux/flutter/generated_plugins.cmake @@ -0,0 +1,23 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST +) + +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/packages/word_segmenter/example/linux/runner/CMakeLists.txt b/packages/word_segmenter/example/linux/runner/CMakeLists.txt new file mode 100644 index 00000000..e97dabc7 --- /dev/null +++ b/packages/word_segmenter/example/linux/runner/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.13) +project(runner LANGUAGES CXX) + +# Define the application target. To change its name, change BINARY_NAME in the +# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer +# work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} + "main.cc" + "my_application.cc" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add preprocessor definitions for the application ID. +add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") + +# Add dependency libraries. Add any application-specific dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) + +target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") diff --git a/packages/word_segmenter/example/linux/runner/main.cc b/packages/word_segmenter/example/linux/runner/main.cc new file mode 100644 index 00000000..e7c5c543 --- /dev/null +++ b/packages/word_segmenter/example/linux/runner/main.cc @@ -0,0 +1,6 @@ +#include "my_application.h" + +int main(int argc, char** argv) { + g_autoptr(MyApplication) app = my_application_new(); + return g_application_run(G_APPLICATION(app), argc, argv); +} diff --git a/packages/word_segmenter/example/linux/runner/my_application.cc b/packages/word_segmenter/example/linux/runner/my_application.cc new file mode 100644 index 00000000..d4e4880d --- /dev/null +++ b/packages/word_segmenter/example/linux/runner/my_application.cc @@ -0,0 +1,148 @@ +#include "my_application.h" + +#include +#ifdef GDK_WINDOWING_X11 +#include +#endif + +#include "flutter/generated_plugin_registrant.h" + +struct _MyApplication { + GtkApplication parent_instance; + char** dart_entrypoint_arguments; +}; + +G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) + +// Called when first Flutter frame received. +static void first_frame_cb(MyApplication* self, FlView* view) { + gtk_widget_show(gtk_widget_get_toplevel(GTK_WIDGET(view))); +} + +// Implements GApplication::activate. +static void my_application_activate(GApplication* application) { + MyApplication* self = MY_APPLICATION(application); + GtkWindow* window = + GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); + + // Use a header bar when running in GNOME as this is the common style used + // by applications and is the setup most users will be using (e.g. Ubuntu + // desktop). + // If running on X and not using GNOME then just use a traditional title bar + // in case the window manager does more exotic layout, e.g. tiling. + // If running on Wayland assume the header bar will work (may need changing + // if future cases occur). + gboolean use_header_bar = TRUE; +#ifdef GDK_WINDOWING_X11 + GdkScreen* screen = gtk_window_get_screen(window); + if (GDK_IS_X11_SCREEN(screen)) { + const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); + if (g_strcmp0(wm_name, "GNOME Shell") != 0) { + use_header_bar = FALSE; + } + } +#endif + if (use_header_bar) { + GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + gtk_widget_show(GTK_WIDGET(header_bar)); + gtk_header_bar_set_title(header_bar, "word_segmenter_example"); + gtk_header_bar_set_show_close_button(header_bar, TRUE); + gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); + } else { + gtk_window_set_title(window, "word_segmenter_example"); + } + + gtk_window_set_default_size(window, 1280, 720); + + g_autoptr(FlDartProject) project = fl_dart_project_new(); + fl_dart_project_set_dart_entrypoint_arguments( + project, self->dart_entrypoint_arguments); + + FlView* view = fl_view_new(project); + GdkRGBA background_color; + // Background defaults to black, override it here if necessary, e.g. #00000000 + // for transparent. + gdk_rgba_parse(&background_color, "#000000"); + fl_view_set_background_color(view, &background_color); + gtk_widget_show(GTK_WIDGET(view)); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); + + // Show the window when Flutter renders. + // Requires the view to be realized so we can start rendering. + g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb), + self); + gtk_widget_realize(GTK_WIDGET(view)); + + fl_register_plugins(FL_PLUGIN_REGISTRY(view)); + + gtk_widget_grab_focus(GTK_WIDGET(view)); +} + +// Implements GApplication::local_command_line. +static gboolean my_application_local_command_line(GApplication* application, + gchar*** arguments, + int* exit_status) { + MyApplication* self = MY_APPLICATION(application); + // Strip out the first argument as it is the binary name. + self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); + + g_autoptr(GError) error = nullptr; + if (!g_application_register(application, nullptr, &error)) { + g_warning("Failed to register: %s", error->message); + *exit_status = 1; + return TRUE; + } + + g_application_activate(application); + *exit_status = 0; + + return TRUE; +} + +// Implements GApplication::startup. +static void my_application_startup(GApplication* application) { + // MyApplication* self = MY_APPLICATION(object); + + // Perform any actions required at application startup. + + G_APPLICATION_CLASS(my_application_parent_class)->startup(application); +} + +// Implements GApplication::shutdown. +static void my_application_shutdown(GApplication* application) { + // MyApplication* self = MY_APPLICATION(object); + + // Perform any actions required at application shutdown. + + G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application); +} + +// Implements GObject::dispose. +static void my_application_dispose(GObject* object) { + MyApplication* self = MY_APPLICATION(object); + g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); + G_OBJECT_CLASS(my_application_parent_class)->dispose(object); +} + +static void my_application_class_init(MyApplicationClass* klass) { + G_APPLICATION_CLASS(klass)->activate = my_application_activate; + G_APPLICATION_CLASS(klass)->local_command_line = + my_application_local_command_line; + G_APPLICATION_CLASS(klass)->startup = my_application_startup; + G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown; + G_OBJECT_CLASS(klass)->dispose = my_application_dispose; +} + +static void my_application_init(MyApplication* self) {} + +MyApplication* my_application_new() { + // Set the program name to the application ID, which helps various systems + // like GTK and desktop environments map this running application to its + // corresponding .desktop file. This ensures better integration by allowing + // the application to be recognized beyond its binary name. + g_set_prgname(APPLICATION_ID); + + return MY_APPLICATION(g_object_new(my_application_get_type(), + "application-id", APPLICATION_ID, "flags", + G_APPLICATION_NON_UNIQUE, nullptr)); +} diff --git a/packages/word_segmenter/example/linux/runner/my_application.h b/packages/word_segmenter/example/linux/runner/my_application.h new file mode 100644 index 00000000..db16367a --- /dev/null +++ b/packages/word_segmenter/example/linux/runner/my_application.h @@ -0,0 +1,21 @@ +#ifndef FLUTTER_MY_APPLICATION_H_ +#define FLUTTER_MY_APPLICATION_H_ + +#include + +G_DECLARE_FINAL_TYPE(MyApplication, + my_application, + MY, + APPLICATION, + GtkApplication) + +/** + * my_application_new: + * + * Creates a new Flutter-based application. + * + * Returns: a new #MyApplication. + */ +MyApplication* my_application_new(); + +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/packages/string_tokenizer/example/macos/.gitignore b/packages/word_segmenter/example/macos/.gitignore similarity index 100% rename from packages/string_tokenizer/example/macos/.gitignore rename to packages/word_segmenter/example/macos/.gitignore diff --git a/packages/word_segmenter/example/macos/Flutter/Flutter-Debug.xcconfig b/packages/word_segmenter/example/macos/Flutter/Flutter-Debug.xcconfig new file mode 100644 index 00000000..c2efd0b6 --- /dev/null +++ b/packages/word_segmenter/example/macos/Flutter/Flutter-Debug.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/packages/word_segmenter/example/macos/Flutter/Flutter-Release.xcconfig b/packages/word_segmenter/example/macos/Flutter/Flutter-Release.xcconfig new file mode 100644 index 00000000..c2efd0b6 --- /dev/null +++ b/packages/word_segmenter/example/macos/Flutter/Flutter-Release.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/packages/string_tokenizer/example/macos/Flutter/GeneratedPluginRegistrant.swift b/packages/word_segmenter/example/macos/Flutter/GeneratedPluginRegistrant.swift similarity index 100% rename from packages/string_tokenizer/example/macos/Flutter/GeneratedPluginRegistrant.swift rename to packages/word_segmenter/example/macos/Flutter/GeneratedPluginRegistrant.swift diff --git a/packages/string_tokenizer/example/macos/Runner.xcodeproj/project.pbxproj b/packages/word_segmenter/example/macos/Runner.xcodeproj/project.pbxproj similarity index 79% rename from packages/string_tokenizer/example/macos/Runner.xcodeproj/project.pbxproj rename to packages/word_segmenter/example/macos/Runner.xcodeproj/project.pbxproj index c964e829..4155ed4b 100644 --- a/packages/string_tokenizer/example/macos/Runner.xcodeproj/project.pbxproj +++ b/packages/word_segmenter/example/macos/Runner.xcodeproj/project.pbxproj @@ -27,8 +27,7 @@ 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; - CF15521FA0824EAEEFCFBE27 /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B13686D1B8F8780F978DD469 /* Pods_RunnerTests.framework */; }; - F51B1F8FAA13CBA4990065EA /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4EFEB285479AF0587E08328E /* Pods_Runner.framework */; }; + 78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -62,12 +61,11 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 0AA5254EBE921662ABD988A7 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 331C80D5294CF71000263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 331C80D7294CF71000263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = ""; }; 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; - 33CC10ED2044A3C60003C045 /* example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10ED2044A3C60003C045 /* word_segmenter_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "word_segmenter_example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; @@ -79,15 +77,9 @@ 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = ""; }; 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; - 4E1EB2AAA8D250BCD6BED2C2 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; - 4EFEB285479AF0587E08328E /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 7855483BAEA1877BB6D16122 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; + 78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterGeneratedPluginSwiftPackage; path = ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; - 8D8FB307591DFC83B44AC301 /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; - B13686D1B8F8780F978DD469 /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - DC72B037A8D777BFB43DB01F /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; - EB1002FD4E09850DC7FB99FD /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -95,7 +87,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - CF15521FA0824EAEEFCFBE27 /* Pods_RunnerTests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -103,7 +94,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - F51B1F8FAA13CBA4990065EA /* Pods_Runner.framework in Frameworks */, + 78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -137,14 +128,13 @@ 331C80D6294CF71000263BE5 /* RunnerTests */, 33CC10EE2044A3C60003C045 /* Products */, D73912EC22F37F3D000D13A0 /* Frameworks */, - BFAC78EE435F5B2ED581DEEC /* Pods */, ); sourceTree = ""; }; 33CC10EE2044A3C60003C045 /* Products */ = { isa = PBXGroup; children = ( - 33CC10ED2044A3C60003C045 /* example.app */, + 33CC10ED2044A3C60003C045 /* word_segmenter_example.app */, 331C80D5294CF71000263BE5 /* RunnerTests.xctest */, ); name = Products; @@ -164,6 +154,7 @@ 33CEB47122A05771004F2AC0 /* Flutter */ = { isa = PBXGroup; children = ( + 78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */, 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */, 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */, @@ -185,25 +176,9 @@ path = Runner; sourceTree = ""; }; - BFAC78EE435F5B2ED581DEEC /* Pods */ = { - isa = PBXGroup; - children = ( - 7855483BAEA1877BB6D16122 /* Pods-Runner.debug.xcconfig */, - DC72B037A8D777BFB43DB01F /* Pods-Runner.release.xcconfig */, - 0AA5254EBE921662ABD988A7 /* Pods-Runner.profile.xcconfig */, - EB1002FD4E09850DC7FB99FD /* Pods-RunnerTests.debug.xcconfig */, - 4E1EB2AAA8D250BCD6BED2C2 /* Pods-RunnerTests.release.xcconfig */, - 8D8FB307591DFC83B44AC301 /* Pods-RunnerTests.profile.xcconfig */, - ); - name = Pods; - path = Pods; - sourceTree = ""; - }; D73912EC22F37F3D000D13A0 /* Frameworks */ = { isa = PBXGroup; children = ( - 4EFEB285479AF0587E08328E /* Pods_Runner.framework */, - B13686D1B8F8780F978DD469 /* Pods_RunnerTests.framework */, ); name = Frameworks; sourceTree = ""; @@ -215,7 +190,6 @@ isa = PBXNativeTarget; buildConfigurationList = 331C80DE294CF71000263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */; buildPhases = ( - F205D61E434640197425D318 /* [CP] Check Pods Manifest.lock */, 331C80D1294CF70F00263BE5 /* Sources */, 331C80D2294CF70F00263BE5 /* Frameworks */, 331C80D3294CF70F00263BE5 /* Resources */, @@ -234,7 +208,6 @@ isa = PBXNativeTarget; buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( - 73DEEE66415CB60604F7C9F9 /* [CP] Check Pods Manifest.lock */, 33CC10E92044A3C60003C045 /* Sources */, 33CC10EA2044A3C60003C045 /* Frameworks */, 33CC10EB2044A3C60003C045 /* Resources */, @@ -247,8 +220,11 @@ 33CC11202044C79F0003C045 /* PBXTargetDependency */, ); name = Runner; + packageProductDependencies = ( + 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */, + ); productName = Runner; - productReference = 33CC10ED2044A3C60003C045 /* example.app */; + productReference = 33CC10ED2044A3C60003C045 /* word_segmenter_example.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ @@ -291,6 +267,9 @@ Base, ); mainGroup = 33CC10E42044A3C60003C045; + packageReferences = ( + 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */, + ); productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -360,50 +339,6 @@ shellPath = /bin/sh; shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; }; - 73DEEE66415CB60604F7C9F9 /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; - F205D61E434640197425D318 /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-RunnerTests-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -455,46 +390,43 @@ /* Begin XCBuildConfiguration section */ 331C80DB294CF71000263BE5 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = EB1002FD4E09850DC7FB99FD /* Pods-RunnerTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.example.example.RunnerTests; + PRODUCT_BUNDLE_IDENTIFIER = com.example.wordSegmenterExample.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/example"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/word_segmenter_example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/word_segmenter_example"; }; name = Debug; }; 331C80DC294CF71000263BE5 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 4E1EB2AAA8D250BCD6BED2C2 /* Pods-RunnerTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.example.example.RunnerTests; + PRODUCT_BUNDLE_IDENTIFIER = com.example.wordSegmenterExample.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/example"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/word_segmenter_example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/word_segmenter_example"; }; name = Release; }; 331C80DD294CF71000263BE5 /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 8D8FB307591DFC83B44AC301 /* Pods-RunnerTests.profile.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.example.example.RunnerTests; + PRODUCT_BUNDLE_IDENTIFIER = com.example.wordSegmenterExample.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/example"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/word_segmenter_example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/word_segmenter_example"; }; name = Profile; }; @@ -539,7 +471,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; @@ -621,7 +553,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -671,7 +603,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; @@ -778,6 +710,20 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCLocalSwiftPackageReference section */ + 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */ = { + isa = XCLocalSwiftPackageReference; + relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; + }; +/* End XCLocalSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */ = { + isa = XCSwiftPackageProductDependency; + productName = FlutterGeneratedPluginSwiftPackage; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 33CC10E52044A3C60003C045 /* Project object */; } diff --git a/packages/string_tokenizer/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/word_segmenter/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from packages/string_tokenizer/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/word_segmenter/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/packages/string_tokenizer/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/word_segmenter/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 75% rename from packages/string_tokenizer/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to packages/word_segmenter/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 15368ecc..36cd25e1 100644 --- a/packages/string_tokenizer/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/word_segmenter/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -5,6 +5,24 @@ + + + + + + + + + + @@ -31,7 +49,7 @@ @@ -59,13 +77,14 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" + enableGPUValidationMode = "1" allowLocationSimulation = "YES"> @@ -82,7 +101,7 @@ diff --git a/packages/string_tokenizer/example/macos/Runner.xcworkspace/contents.xcworkspacedata b/packages/word_segmenter/example/macos/Runner.xcworkspace/contents.xcworkspacedata similarity index 67% rename from packages/string_tokenizer/example/macos/Runner.xcworkspace/contents.xcworkspacedata rename to packages/word_segmenter/example/macos/Runner.xcworkspace/contents.xcworkspacedata index 21a3cc14..1d526a16 100644 --- a/packages/string_tokenizer/example/macos/Runner.xcworkspace/contents.xcworkspacedata +++ b/packages/word_segmenter/example/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -4,7 +4,4 @@ - - diff --git a/packages/string_tokenizer/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/word_segmenter/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from packages/string_tokenizer/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/word_segmenter/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/packages/string_tokenizer/example/macos/Runner/AppDelegate.swift b/packages/word_segmenter/example/macos/Runner/AppDelegate.swift similarity index 64% rename from packages/string_tokenizer/example/macos/Runner/AppDelegate.swift rename to packages/word_segmenter/example/macos/Runner/AppDelegate.swift index 8e02df28..b3c17614 100644 --- a/packages/string_tokenizer/example/macos/Runner/AppDelegate.swift +++ b/packages/word_segmenter/example/macos/Runner/AppDelegate.swift @@ -6,4 +6,8 @@ class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } } diff --git a/packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png b/packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png rename to packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png diff --git a/packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png b/packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png rename to packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png diff --git a/packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png b/packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png rename to packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png diff --git a/packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png b/packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png rename to packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png diff --git a/packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png b/packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png rename to packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png diff --git a/packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png b/packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png rename to packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png diff --git a/packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png b/packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png rename to packages/word_segmenter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png diff --git a/packages/string_tokenizer/example/macos/Runner/Base.lproj/MainMenu.xib b/packages/word_segmenter/example/macos/Runner/Base.lproj/MainMenu.xib similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Base.lproj/MainMenu.xib rename to packages/word_segmenter/example/macos/Runner/Base.lproj/MainMenu.xib diff --git a/packages/string_tokenizer/example/macos/Runner/Configs/AppInfo.xcconfig b/packages/word_segmenter/example/macos/Runner/Configs/AppInfo.xcconfig similarity index 74% rename from packages/string_tokenizer/example/macos/Runner/Configs/AppInfo.xcconfig rename to packages/word_segmenter/example/macos/Runner/Configs/AppInfo.xcconfig index 92fb3cd5..04fe8909 100644 --- a/packages/string_tokenizer/example/macos/Runner/Configs/AppInfo.xcconfig +++ b/packages/word_segmenter/example/macos/Runner/Configs/AppInfo.xcconfig @@ -5,10 +5,10 @@ // 'flutter create' template. // The application's name. By default this is also the title of the Flutter window. -PRODUCT_NAME = example +PRODUCT_NAME = word_segmenter_example // The application's bundle identifier -PRODUCT_BUNDLE_IDENTIFIER = com.example.example +PRODUCT_BUNDLE_IDENTIFIER = com.example.wordSegmenterExample // The copyright displayed in application information -PRODUCT_COPYRIGHT = Copyright © 2024 com.example. All rights reserved. +PRODUCT_COPYRIGHT = Copyright © 2026 com.example. All rights reserved. diff --git a/packages/string_tokenizer/example/macos/Runner/Configs/Debug.xcconfig b/packages/word_segmenter/example/macos/Runner/Configs/Debug.xcconfig similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Configs/Debug.xcconfig rename to packages/word_segmenter/example/macos/Runner/Configs/Debug.xcconfig diff --git a/packages/string_tokenizer/example/macos/Runner/Configs/Release.xcconfig b/packages/word_segmenter/example/macos/Runner/Configs/Release.xcconfig similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Configs/Release.xcconfig rename to packages/word_segmenter/example/macos/Runner/Configs/Release.xcconfig diff --git a/packages/string_tokenizer/example/macos/Runner/Configs/Warnings.xcconfig b/packages/word_segmenter/example/macos/Runner/Configs/Warnings.xcconfig similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Configs/Warnings.xcconfig rename to packages/word_segmenter/example/macos/Runner/Configs/Warnings.xcconfig diff --git a/packages/string_tokenizer/example/macos/Runner/DebugProfile.entitlements b/packages/word_segmenter/example/macos/Runner/DebugProfile.entitlements similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/DebugProfile.entitlements rename to packages/word_segmenter/example/macos/Runner/DebugProfile.entitlements diff --git a/packages/string_tokenizer/example/macos/Runner/Info.plist b/packages/word_segmenter/example/macos/Runner/Info.plist similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Info.plist rename to packages/word_segmenter/example/macos/Runner/Info.plist diff --git a/packages/string_tokenizer/example/macos/Runner/MainFlutterWindow.swift b/packages/word_segmenter/example/macos/Runner/MainFlutterWindow.swift similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/MainFlutterWindow.swift rename to packages/word_segmenter/example/macos/Runner/MainFlutterWindow.swift diff --git a/packages/string_tokenizer/example/macos/Runner/Release.entitlements b/packages/word_segmenter/example/macos/Runner/Release.entitlements similarity index 100% rename from packages/string_tokenizer/example/macos/Runner/Release.entitlements rename to packages/word_segmenter/example/macos/Runner/Release.entitlements diff --git a/packages/string_tokenizer/example/macos/RunnerTests/RunnerTests.swift b/packages/word_segmenter/example/macos/RunnerTests/RunnerTests.swift similarity index 100% rename from packages/string_tokenizer/example/macos/RunnerTests/RunnerTests.swift rename to packages/word_segmenter/example/macos/RunnerTests/RunnerTests.swift diff --git a/packages/word_segmenter/example/pubspec.yaml b/packages/word_segmenter/example/pubspec.yaml new file mode 100644 index 00000000..58cc8f11 --- /dev/null +++ b/packages/word_segmenter/example/pubspec.yaml @@ -0,0 +1,25 @@ +name: word_segmenter_example +resolution: workspace +description: Demonstrates how to use the word_segmenter package. +publish_to: 'none' + +version: 1.0.0+1 + +environment: + sdk: ^3.6.0 + +dependencies: + flutter: + sdk: flutter + word_segmenter: + path: ../ + +dev_dependencies: + flutter_test: + sdk: flutter + integration_test: + sdk: flutter + flutter_lints: ^6.0.0 + +flutter: + uses-material-design: true diff --git a/packages/word_segmenter/example/web/favicon.png b/packages/word_segmenter/example/web/favicon.png new file mode 100644 index 00000000..8aaa46ac Binary files /dev/null and b/packages/word_segmenter/example/web/favicon.png differ diff --git a/packages/word_segmenter/example/web/icons/Icon-192.png b/packages/word_segmenter/example/web/icons/Icon-192.png new file mode 100644 index 00000000..b749bfef Binary files /dev/null and b/packages/word_segmenter/example/web/icons/Icon-192.png differ diff --git a/packages/word_segmenter/example/web/icons/Icon-512.png b/packages/word_segmenter/example/web/icons/Icon-512.png new file mode 100644 index 00000000..88cfd48d Binary files /dev/null and b/packages/word_segmenter/example/web/icons/Icon-512.png differ diff --git a/packages/word_segmenter/example/web/icons/Icon-maskable-192.png b/packages/word_segmenter/example/web/icons/Icon-maskable-192.png new file mode 100644 index 00000000..eb9b4d76 Binary files /dev/null and b/packages/word_segmenter/example/web/icons/Icon-maskable-192.png differ diff --git a/packages/word_segmenter/example/web/icons/Icon-maskable-512.png b/packages/word_segmenter/example/web/icons/Icon-maskable-512.png new file mode 100644 index 00000000..d69c5669 Binary files /dev/null and b/packages/word_segmenter/example/web/icons/Icon-maskable-512.png differ diff --git a/packages/word_segmenter/example/web/index.html b/packages/word_segmenter/example/web/index.html new file mode 100644 index 00000000..c3fe216c --- /dev/null +++ b/packages/word_segmenter/example/web/index.html @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + word_segmenter_example + + + + + + + diff --git a/packages/word_segmenter/example/web/manifest.json b/packages/word_segmenter/example/web/manifest.json new file mode 100644 index 00000000..4e8a99a6 --- /dev/null +++ b/packages/word_segmenter/example/web/manifest.json @@ -0,0 +1,35 @@ +{ + "name": "word_segmenter_example", + "short_name": "word_segmenter_example", + "start_url": ".", + "display": "standalone", + "background_color": "#0175C2", + "theme_color": "#0175C2", + "description": "A new Flutter project.", + "orientation": "portrait-primary", + "prefer_related_applications": false, + "icons": [ + { + "src": "icons/Icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/Icon-512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + } + ] +} diff --git a/packages/word_segmenter/example/windows/.gitignore b/packages/word_segmenter/example/windows/.gitignore new file mode 100644 index 00000000..d492d0d9 --- /dev/null +++ b/packages/word_segmenter/example/windows/.gitignore @@ -0,0 +1,17 @@ +flutter/ephemeral/ + +# Visual Studio user-specific files. +*.suo +*.user +*.userosscache +*.sln.docstates + +# Visual Studio build-related files. +x64/ +x86/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ diff --git a/packages/word_segmenter/example/windows/CMakeLists.txt b/packages/word_segmenter/example/windows/CMakeLists.txt new file mode 100644 index 00000000..daa482b2 --- /dev/null +++ b/packages/word_segmenter/example/windows/CMakeLists.txt @@ -0,0 +1,108 @@ +# Project-level configuration. +cmake_minimum_required(VERSION 3.14) +project(word_segmenter_example LANGUAGES CXX) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "word_segmenter_example") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(VERSION 3.14...3.25) + +# Define build configuration option. +get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(IS_MULTICONFIG) + set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" + CACHE STRING "" FORCE) +else() + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") + endif() +endif() +# Define settings for the Profile build mode. +set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") +set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") +set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") + +# Use Unicode for all projects. +add_definitions(-DUNICODE -D_UNICODE) + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_17) + target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") + target_compile_options(${TARGET} PRIVATE /EHsc) + target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") + target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# Application build; see runner/CMakeLists.txt. +add_subdirectory("runner") + + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# Support files are copied into place next to the executable, so that it can +# run in place. This is done instead of making a separate bundle (as on Linux) +# so that building and running from within Visual Studio will work. +set(BUILD_BUNDLE_DIR "$") +# Make the "install" step default, as it's required to run. +set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Copy the native assets provided by the build.dart from all packages. +set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") +install(DIRECTORY "${NATIVE_ASSETS_DIR}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + CONFIGURATIONS Profile;Release + COMPONENT Runtime) diff --git a/packages/word_segmenter/example/windows/flutter/CMakeLists.txt b/packages/word_segmenter/example/windows/flutter/CMakeLists.txt new file mode 100644 index 00000000..903f4899 --- /dev/null +++ b/packages/word_segmenter/example/windows/flutter/CMakeLists.txt @@ -0,0 +1,109 @@ +# This file controls Flutter-level build steps. It should not be edited. +cmake_minimum_required(VERSION 3.14) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. +set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") + +# Set fallback configurations for older versions of the flutter tool. +if (NOT DEFINED FLUTTER_TARGET_PLATFORM) + set(FLUTTER_TARGET_PLATFORM "windows-x64") +endif() + +# === Flutter Library === +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "flutter_export.h" + "flutter_windows.h" + "flutter_messenger.h" + "flutter_plugin_registrar.h" + "flutter_texture_registrar.h" +) +list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") +add_dependencies(flutter flutter_assemble) + +# === Wrapper === +list(APPEND CPP_WRAPPER_SOURCES_CORE + "core_implementations.cc" + "standard_codec.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_PLUGIN + "plugin_registrar.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_APP + "flutter_engine.cc" + "flutter_view_controller.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") + +# Wrapper sources needed for a plugin. +add_library(flutter_wrapper_plugin STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} +) +apply_standard_settings(flutter_wrapper_plugin) +set_target_properties(flutter_wrapper_plugin PROPERTIES + POSITION_INDEPENDENT_CODE ON) +set_target_properties(flutter_wrapper_plugin PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) +target_include_directories(flutter_wrapper_plugin PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_plugin flutter_assemble) + +# Wrapper sources needed for the runner. +add_library(flutter_wrapper_app STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_APP} +) +apply_standard_settings(flutter_wrapper_app) +target_link_libraries(flutter_wrapper_app PUBLIC flutter) +target_include_directories(flutter_wrapper_app PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_app flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") +set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} + ${PHONY_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" + ${FLUTTER_TARGET_PLATFORM} $ + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} +) diff --git a/packages/word_segmenter/example/windows/flutter/generated_plugin_registrant.cc b/packages/word_segmenter/example/windows/flutter/generated_plugin_registrant.cc new file mode 100644 index 00000000..8b6d4680 --- /dev/null +++ b/packages/word_segmenter/example/windows/flutter/generated_plugin_registrant.cc @@ -0,0 +1,11 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + + +void RegisterPlugins(flutter::PluginRegistry* registry) { +} diff --git a/packages/word_segmenter/example/windows/flutter/generated_plugin_registrant.h b/packages/word_segmenter/example/windows/flutter/generated_plugin_registrant.h new file mode 100644 index 00000000..dc139d85 --- /dev/null +++ b/packages/word_segmenter/example/windows/flutter/generated_plugin_registrant.h @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void RegisterPlugins(flutter::PluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/packages/word_segmenter/example/windows/flutter/generated_plugins.cmake b/packages/word_segmenter/example/windows/flutter/generated_plugins.cmake new file mode 100644 index 00000000..b93c4c30 --- /dev/null +++ b/packages/word_segmenter/example/windows/flutter/generated_plugins.cmake @@ -0,0 +1,23 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST +) + +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/packages/word_segmenter/example/windows/runner/CMakeLists.txt b/packages/word_segmenter/example/windows/runner/CMakeLists.txt new file mode 100644 index 00000000..394917c0 --- /dev/null +++ b/packages/word_segmenter/example/windows/runner/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.14) +project(runner LANGUAGES CXX) + +# Define the application target. To change its name, change BINARY_NAME in the +# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer +# work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} WIN32 + "flutter_window.cpp" + "main.cpp" + "utils.cpp" + "win32_window.cpp" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" + "Runner.rc" + "runner.exe.manifest" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add preprocessor definitions for the build version. +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") + +# Disable Windows macros that collide with C++ standard library functions. +target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") + +# Add dependency libraries and include directories. Add any application-specific +# dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) +target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") +target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) diff --git a/packages/word_segmenter/example/windows/runner/Runner.rc b/packages/word_segmenter/example/windows/runner/Runner.rc new file mode 100644 index 00000000..936d892d --- /dev/null +++ b/packages/word_segmenter/example/windows/runner/Runner.rc @@ -0,0 +1,121 @@ +// Microsoft Visual C++ generated resource script. +// +#pragma code_page(65001) +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_APP_ICON ICON "resources\\app_icon.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) +#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD +#else +#define VERSION_AS_NUMBER 1,0,0,0 +#endif + +#if defined(FLUTTER_VERSION) +#define VERSION_AS_STRING FLUTTER_VERSION +#else +#define VERSION_AS_STRING "1.0.0" +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VERSION_AS_NUMBER + PRODUCTVERSION VERSION_AS_NUMBER + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "com.example" "\0" + VALUE "FileDescription", "word_segmenter_example" "\0" + VALUE "FileVersion", VERSION_AS_STRING "\0" + VALUE "InternalName", "word_segmenter_example" "\0" + VALUE "LegalCopyright", "Copyright (C) 2026 com.example. All rights reserved." "\0" + VALUE "OriginalFilename", "word_segmenter_example.exe" "\0" + VALUE "ProductName", "word_segmenter_example" "\0" + VALUE "ProductVersion", VERSION_AS_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/packages/word_segmenter/example/windows/runner/flutter_window.cpp b/packages/word_segmenter/example/windows/runner/flutter_window.cpp new file mode 100644 index 00000000..955ee303 --- /dev/null +++ b/packages/word_segmenter/example/windows/runner/flutter_window.cpp @@ -0,0 +1,71 @@ +#include "flutter_window.h" + +#include + +#include "flutter/generated_plugin_registrant.h" + +FlutterWindow::FlutterWindow(const flutter::DartProject& project) + : project_(project) {} + +FlutterWindow::~FlutterWindow() {} + +bool FlutterWindow::OnCreate() { + if (!Win32Window::OnCreate()) { + return false; + } + + RECT frame = GetClientArea(); + + // The size here must match the window dimensions to avoid unnecessary surface + // creation / destruction in the startup path. + flutter_controller_ = std::make_unique( + frame.right - frame.left, frame.bottom - frame.top, project_); + // Ensure that basic setup of the controller was successful. + if (!flutter_controller_->engine() || !flutter_controller_->view()) { + return false; + } + RegisterPlugins(flutter_controller_->engine()); + SetChildContent(flutter_controller_->view()->GetNativeWindow()); + + flutter_controller_->engine()->SetNextFrameCallback([&]() { + this->Show(); + }); + + // Flutter can complete the first frame before the "show window" callback is + // registered. The following call ensures a frame is pending to ensure the + // window is shown. It is a no-op if the first frame hasn't completed yet. + flutter_controller_->ForceRedraw(); + + return true; +} + +void FlutterWindow::OnDestroy() { + if (flutter_controller_) { + flutter_controller_ = nullptr; + } + + Win32Window::OnDestroy(); +} + +LRESULT +FlutterWindow::MessageHandler(HWND hwnd, UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + // Give Flutter, including plugins, an opportunity to handle window messages. + if (flutter_controller_) { + std::optional result = + flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, + lparam); + if (result) { + return *result; + } + } + + switch (message) { + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; + } + + return Win32Window::MessageHandler(hwnd, message, wparam, lparam); +} diff --git a/packages/word_segmenter/example/windows/runner/flutter_window.h b/packages/word_segmenter/example/windows/runner/flutter_window.h new file mode 100644 index 00000000..6da0652f --- /dev/null +++ b/packages/word_segmenter/example/windows/runner/flutter_window.h @@ -0,0 +1,33 @@ +#ifndef RUNNER_FLUTTER_WINDOW_H_ +#define RUNNER_FLUTTER_WINDOW_H_ + +#include +#include + +#include + +#include "win32_window.h" + +// A window that does nothing but host a Flutter view. +class FlutterWindow : public Win32Window { + public: + // Creates a new FlutterWindow hosting a Flutter view running |project|. + explicit FlutterWindow(const flutter::DartProject& project); + virtual ~FlutterWindow(); + + protected: + // Win32Window: + bool OnCreate() override; + void OnDestroy() override; + LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, + LPARAM const lparam) noexcept override; + + private: + // The project to run. + flutter::DartProject project_; + + // The Flutter instance hosted by this window. + std::unique_ptr flutter_controller_; +}; + +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/packages/word_segmenter/example/windows/runner/main.cpp b/packages/word_segmenter/example/windows/runner/main.cpp new file mode 100644 index 00000000..de1bd6b0 --- /dev/null +++ b/packages/word_segmenter/example/windows/runner/main.cpp @@ -0,0 +1,43 @@ +#include +#include +#include + +#include "flutter_window.h" +#include "utils.h" + +int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, + _In_ wchar_t *command_line, _In_ int show_command) { + // Attach to console when present (e.g., 'flutter run') or create a + // new console when running with a debugger. + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { + CreateAndAttachConsole(); + } + + // Initialize COM, so that it is available for use in the library and/or + // plugins. + ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + flutter::DartProject project(L"data"); + + std::vector command_line_arguments = + GetCommandLineArguments(); + + project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); + + FlutterWindow window(project); + Win32Window::Point origin(10, 10); + Win32Window::Size size(1280, 720); + if (!window.Create(L"word_segmenter_example", origin, size)) { + return EXIT_FAILURE; + } + window.SetQuitOnClose(true); + + ::MSG msg; + while (::GetMessage(&msg, nullptr, 0, 0)) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + + ::CoUninitialize(); + return EXIT_SUCCESS; +} diff --git a/packages/word_segmenter/example/windows/runner/resource.h b/packages/word_segmenter/example/windows/runner/resource.h new file mode 100644 index 00000000..66a65d1e --- /dev/null +++ b/packages/word_segmenter/example/windows/runner/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Runner.rc +// +#define IDI_APP_ICON 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/packages/word_segmenter/example/windows/runner/resources/app_icon.ico b/packages/word_segmenter/example/windows/runner/resources/app_icon.ico new file mode 100644 index 00000000..c04e20ca Binary files /dev/null and b/packages/word_segmenter/example/windows/runner/resources/app_icon.ico differ diff --git a/packages/word_segmenter/example/windows/runner/runner.exe.manifest b/packages/word_segmenter/example/windows/runner/runner.exe.manifest new file mode 100644 index 00000000..153653e8 --- /dev/null +++ b/packages/word_segmenter/example/windows/runner/runner.exe.manifest @@ -0,0 +1,14 @@ + + + + + PerMonitorV2 + + + + + + + + + diff --git a/packages/word_segmenter/example/windows/runner/utils.cpp b/packages/word_segmenter/example/windows/runner/utils.cpp new file mode 100644 index 00000000..3cb71466 --- /dev/null +++ b/packages/word_segmenter/example/windows/runner/utils.cpp @@ -0,0 +1,69 @@ +#include "utils.h" + +#include +#include +#include +#include + +#include + +void CreateAndAttachConsole() { + if (::AllocConsole()) { + FILE *unused; + if (freopen_s(&unused, "CONOUT$", "w", stdout)) { + _dup2(_fileno(stdout), 1); + } + if (freopen_s(&unused, "CONOUT$", "w", stderr)) { + _dup2(_fileno(stdout), 2); + } + std::ios::sync_with_stdio(); + FlutterDesktopResyncOutputStreams(); + } +} + +std::vector GetCommandLineArguments() { + // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. + int argc; + wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + if (argv == nullptr) { + return std::vector(); + } + + std::vector command_line_arguments; + + // Skip the first argument as it's the binary name. + for (int i = 1; i < argc; i++) { + command_line_arguments.push_back(Utf8FromUtf16(argv[i])); + } + + ::LocalFree(argv); + + return command_line_arguments; +} + +std::string Utf8FromUtf16(const wchar_t* utf16_string) { + if (utf16_string == nullptr) { + return std::string(); + } + // First, find the length of the string with a safe upper bound (CWE-126). + // UNICODE_STRING_MAX_CHARS (32767) is the maximum length of a UNICODE_STRING. + int input_length = static_cast(wcsnlen(utf16_string, UNICODE_STRING_MAX_CHARS)); + // Now use that bounded length to determine the required buffer size. + // When an explicit length is passed, WideCharToMultiByte does not include + // the null terminator in its returned size. + int target_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + input_length, nullptr, 0, nullptr, nullptr); + std::string utf8_string; + if (target_length == 0 || static_cast(target_length) > utf8_string.max_size()) { + return utf8_string; + } + utf8_string.resize(target_length); + int converted_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + input_length, utf8_string.data(), target_length, nullptr, nullptr); + if (converted_length == 0) { + return std::string(); + } + return utf8_string; +} diff --git a/packages/word_segmenter/example/windows/runner/utils.h b/packages/word_segmenter/example/windows/runner/utils.h new file mode 100644 index 00000000..3879d547 --- /dev/null +++ b/packages/word_segmenter/example/windows/runner/utils.h @@ -0,0 +1,19 @@ +#ifndef RUNNER_UTILS_H_ +#define RUNNER_UTILS_H_ + +#include +#include + +// Creates a console for the process, and redirects stdout and stderr to +// it for both the runner and the Flutter library. +void CreateAndAttachConsole(); + +// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string +// encoded in UTF-8. Returns an empty std::string on failure. +std::string Utf8FromUtf16(const wchar_t* utf16_string); + +// Gets the command line arguments passed in as a std::vector, +// encoded in UTF-8. Returns an empty std::vector on failure. +std::vector GetCommandLineArguments(); + +#endif // RUNNER_UTILS_H_ diff --git a/packages/word_segmenter/example/windows/runner/win32_window.cpp b/packages/word_segmenter/example/windows/runner/win32_window.cpp new file mode 100644 index 00000000..60608d0f --- /dev/null +++ b/packages/word_segmenter/example/windows/runner/win32_window.cpp @@ -0,0 +1,288 @@ +#include "win32_window.h" + +#include +#include + +#include "resource.h" + +namespace { + +/// Window attribute that enables dark mode window decorations. +/// +/// Redefined in case the developer's machine has a Windows SDK older than +/// version 10.0.22000.0. +/// See: https://docs.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 +#endif + +constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; + +/// Registry key for app theme preference. +/// +/// A value of 0 indicates apps should use dark mode. A non-zero or missing +/// value indicates apps should use light mode. +constexpr const wchar_t kGetPreferredBrightnessRegKey[] = + L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; +constexpr const wchar_t kGetPreferredBrightnessRegValue[] = L"AppsUseLightTheme"; + +// The number of Win32Window objects that currently exist. +static int g_active_window_count = 0; + +using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); + +// Scale helper to convert logical scaler values to physical using passed in +// scale factor +int Scale(int source, double scale_factor) { + return static_cast(source * scale_factor); +} + +// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. +// This API is only needed for PerMonitor V1 awareness mode. +void EnableFullDpiSupportIfAvailable(HWND hwnd) { + HMODULE user32_module = LoadLibraryA("User32.dll"); + if (!user32_module) { + return; + } + auto enable_non_client_dpi_scaling = + reinterpret_cast( + GetProcAddress(user32_module, "EnableNonClientDpiScaling")); + if (enable_non_client_dpi_scaling != nullptr) { + enable_non_client_dpi_scaling(hwnd); + } + FreeLibrary(user32_module); +} + +} // namespace + +// Manages the Win32Window's window class registration. +class WindowClassRegistrar { + public: + ~WindowClassRegistrar() = default; + + // Returns the singleton registrar instance. + static WindowClassRegistrar* GetInstance() { + if (!instance_) { + instance_ = new WindowClassRegistrar(); + } + return instance_; + } + + // Returns the name of the window class, registering the class if it hasn't + // previously been registered. + const wchar_t* GetWindowClass(); + + // Unregisters the window class. Should only be called if there are no + // instances of the window. + void UnregisterWindowClass(); + + private: + WindowClassRegistrar() = default; + + static WindowClassRegistrar* instance_; + + bool class_registered_ = false; +}; + +WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; + +const wchar_t* WindowClassRegistrar::GetWindowClass() { + if (!class_registered_) { + WNDCLASS window_class{}; + window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); + window_class.lpszClassName = kWindowClassName; + window_class.style = CS_HREDRAW | CS_VREDRAW; + window_class.cbClsExtra = 0; + window_class.cbWndExtra = 0; + window_class.hInstance = GetModuleHandle(nullptr); + window_class.hIcon = + LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); + window_class.hbrBackground = 0; + window_class.lpszMenuName = nullptr; + window_class.lpfnWndProc = Win32Window::WndProc; + RegisterClass(&window_class); + class_registered_ = true; + } + return kWindowClassName; +} + +void WindowClassRegistrar::UnregisterWindowClass() { + UnregisterClass(kWindowClassName, nullptr); + class_registered_ = false; +} + +Win32Window::Win32Window() { + ++g_active_window_count; +} + +Win32Window::~Win32Window() { + --g_active_window_count; + Destroy(); +} + +bool Win32Window::Create(const std::wstring& title, + const Point& origin, + const Size& size) { + Destroy(); + + const wchar_t* window_class = + WindowClassRegistrar::GetInstance()->GetWindowClass(); + + const POINT target_point = {static_cast(origin.x), + static_cast(origin.y)}; + HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); + UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); + double scale_factor = dpi / 96.0; + + HWND window = CreateWindow( + window_class, title.c_str(), WS_OVERLAPPEDWINDOW, + Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), + Scale(size.width, scale_factor), Scale(size.height, scale_factor), + nullptr, nullptr, GetModuleHandle(nullptr), this); + + if (!window) { + return false; + } + + UpdateTheme(window); + + return OnCreate(); +} + +bool Win32Window::Show() { + return ShowWindow(window_handle_, SW_SHOWNORMAL); +} + +// static +LRESULT CALLBACK Win32Window::WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + if (message == WM_NCCREATE) { + auto window_struct = reinterpret_cast(lparam); + SetWindowLongPtr(window, GWLP_USERDATA, + reinterpret_cast(window_struct->lpCreateParams)); + + auto that = static_cast(window_struct->lpCreateParams); + EnableFullDpiSupportIfAvailable(window); + that->window_handle_ = window; + } else if (Win32Window* that = GetThisFromHandle(window)) { + return that->MessageHandler(window, message, wparam, lparam); + } + + return DefWindowProc(window, message, wparam, lparam); +} + +LRESULT +Win32Window::MessageHandler(HWND hwnd, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + switch (message) { + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + } + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; + + case WM_DWMCOLORIZATIONCOLORCHANGED: + UpdateTheme(hwnd); + return 0; + } + + return DefWindowProc(window_handle_, message, wparam, lparam); +} + +void Win32Window::Destroy() { + OnDestroy(); + + if (window_handle_) { + DestroyWindow(window_handle_); + window_handle_ = nullptr; + } + if (g_active_window_count == 0) { + WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); + } +} + +Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( + GetWindowLongPtr(window, GWLP_USERDATA)); +} + +void Win32Window::SetChildContent(HWND content) { + child_content_ = content; + SetParent(content, window_handle_); + RECT frame = GetClientArea(); + + MoveWindow(content, frame.left, frame.top, frame.right - frame.left, + frame.bottom - frame.top, true); + + SetFocus(child_content_); +} + +RECT Win32Window::GetClientArea() { + RECT frame; + GetClientRect(window_handle_, &frame); + return frame; +} + +HWND Win32Window::GetHandle() { + return window_handle_; +} + +void Win32Window::SetQuitOnClose(bool quit_on_close) { + quit_on_close_ = quit_on_close; +} + +bool Win32Window::OnCreate() { + // No-op; provided for subclasses. + return true; +} + +void Win32Window::OnDestroy() { + // No-op; provided for subclasses. +} + +void Win32Window::UpdateTheme(HWND const window) { + DWORD light_mode; + DWORD light_mode_size = sizeof(light_mode); + LSTATUS result = RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey, + kGetPreferredBrightnessRegValue, + RRF_RT_REG_DWORD, nullptr, &light_mode, + &light_mode_size); + + if (result == ERROR_SUCCESS) { + BOOL enable_dark_mode = light_mode == 0; + DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE, + &enable_dark_mode, sizeof(enable_dark_mode)); + } +} diff --git a/packages/word_segmenter/example/windows/runner/win32_window.h b/packages/word_segmenter/example/windows/runner/win32_window.h new file mode 100644 index 00000000..e901dde6 --- /dev/null +++ b/packages/word_segmenter/example/windows/runner/win32_window.h @@ -0,0 +1,102 @@ +#ifndef RUNNER_WIN32_WINDOW_H_ +#define RUNNER_WIN32_WINDOW_H_ + +#include + +#include +#include +#include + +// A class abstraction for a high DPI-aware Win32 Window. Intended to be +// inherited from by classes that wish to specialize with custom +// rendering and input handling +class Win32Window { + public: + struct Point { + unsigned int x; + unsigned int y; + Point(unsigned int x, unsigned int y) : x(x), y(y) {} + }; + + struct Size { + unsigned int width; + unsigned int height; + Size(unsigned int width, unsigned int height) + : width(width), height(height) {} + }; + + Win32Window(); + virtual ~Win32Window(); + + // Creates a win32 window with |title| that is positioned and sized using + // |origin| and |size|. New windows are created on the default monitor. Window + // sizes are specified to the OS in physical pixels, hence to ensure a + // consistent size this function will scale the inputted width and height as + // as appropriate for the default monitor. The window is invisible until + // |Show| is called. Returns true if the window was created successfully. + bool Create(const std::wstring& title, const Point& origin, const Size& size); + + // Show the current window. Returns true if the window was successfully shown. + bool Show(); + + // Release OS resources associated with window. + void Destroy(); + + // Inserts |content| into the window tree. + void SetChildContent(HWND content); + + // Returns the backing Window handle to enable clients to set icon and other + // window properties. Returns nullptr if the window has been destroyed. + HWND GetHandle(); + + // If true, closing this window will quit the application. + void SetQuitOnClose(bool quit_on_close); + + // Return a RECT representing the bounds of the current client area. + RECT GetClientArea(); + + protected: + // Processes and route salient window messages for mouse handling, + // size change and DPI. Delegates handling of these to member overloads that + // inheriting classes can handle. + virtual LRESULT MessageHandler(HWND window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Called when CreateAndShow is called, allowing subclass window-related + // setup. Subclasses should return false if setup fails. + virtual bool OnCreate(); + + // Called when Destroy is called. + virtual void OnDestroy(); + + private: + friend class WindowClassRegistrar; + + // OS callback called by message pump. Handles the WM_NCCREATE message which + // is passed when the non-client area is being created and enables automatic + // non-client DPI scaling so that the non-client area automatically + // responds to changes in DPI. All other messages are handled by + // MessageHandler. + static LRESULT CALLBACK WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Retrieves a class instance pointer for |window| + static Win32Window* GetThisFromHandle(HWND const window) noexcept; + + // Update the window frame's theme to match the system theme. + static void UpdateTheme(HWND const window); + + bool quit_on_close_ = false; + + // window handle for top level window. + HWND window_handle_ = nullptr; + + // window handle for hosted content. + HWND child_content_ = nullptr; +}; + +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/packages/word_segmenter/lib/src/core_foundation.dart b/packages/word_segmenter/lib/src/core_foundation.dart new file mode 100644 index 00000000..80f52160 --- /dev/null +++ b/packages/word_segmenter/lib/src/core_foundation.dart @@ -0,0 +1,95 @@ +import 'dart:ffi'; +import 'dart:ui' show TextRange; + +import 'segmenter_native.dart'; + +final class _CFRange extends Struct { + @Long() + external int location; + + @Long() + external int length; +} + +typedef _CreateStringNative = Pointer Function( + Pointer allocator, + Pointer chars, + Long length, +); +typedef _CreateString = Pointer Function( + Pointer allocator, + Pointer chars, + int length, +); +typedef _CreateTokenizerNative = Pointer Function( + Pointer allocator, + Pointer string, + _CFRange range, + UnsignedLong options, + Pointer locale, +); +typedef _CreateTokenizer = Pointer Function( + Pointer allocator, + Pointer string, + _CFRange range, + int options, + Pointer locale, +); + +const _kCFStringTokenizerUnitWordBoundary = 4; +const _kCFStringTokenizerTokenNone = 0; + +/// Word boundaries from `CFStringTokenizer`, the segmenter behind native text +/// views on Apple platforms. +NativeWordBoundaries? loadCoreFoundation() { + final _CreateString createString; + final _CreateTokenizer createTokenizer; + final int Function(Pointer) advance; + final _CFRange Function(Pointer) currentRange; + final void Function(Pointer) release; + try { + final library = DynamicLibrary.process(); + createString = library.lookupFunction<_CreateStringNative, _CreateString>( + 'CFStringCreateWithCharacters'); + createTokenizer = + library.lookupFunction<_CreateTokenizerNative, _CreateTokenizer>( + 'CFStringTokenizerCreate'); + advance = library.lookupFunction), + int Function(Pointer)>('CFStringTokenizerAdvanceToNextToken'); + currentRange = library.lookupFunction< + _CFRange Function(Pointer), + _CFRange Function( + Pointer)>('CFStringTokenizerGetCurrentTokenRange'); + release = library.lookupFunction), + void Function(Pointer)>('CFRelease'); + } on ArgumentError { + return null; + } + + return (units, length) { + final string = createString(nullptr, units, length); + if (string == nullptr) { + return null; + } + final range = Struct.create<_CFRange>() + ..location = 0 + ..length = length; + final tokenizer = createTokenizer( + nullptr, + string, + range, + _kCFStringTokenizerUnitWordBoundary, + nullptr, + ); + final segments = []; + while (advance(tokenizer) != _kCFStringTokenizerTokenNone) { + final token = currentRange(tokenizer); + segments.add( + TextRange(start: token.location, end: token.location + token.length), + ); + } + release(tokenizer); + release(string); + return segments; + }; +} diff --git a/packages/word_segmenter/lib/src/icu.dart b/packages/word_segmenter/lib/src/icu.dart new file mode 100644 index 00000000..0816353d --- /dev/null +++ b/packages/word_segmenter/lib/src/icu.dart @@ -0,0 +1,92 @@ +import 'dart:ffi'; +import 'dart:io'; +import 'dart:ui' show TextRange; + +import 'package:ffi/ffi.dart'; + +import 'segmenter_native.dart'; + +typedef _OpenNative = Pointer Function( + Int32 type, + Pointer locale, + Pointer text, + Int32 length, + Pointer status, +); +typedef _Open = Pointer Function( + int type, + Pointer locale, + Pointer text, + int length, + Pointer status, +); + +const _ubrkWord = 1; +const _ubrkDone = -1; + +/// Word boundaries from the system ICU break iterator. +/// +/// Flutter's engine ships its own ICU without the CJK dictionary, so this +/// loads the copy that comes with the operating system instead. +NativeWordBoundaries? loadIcu() { + for (final (name, suffix) in _candidates()) { + final segmenter = _tryLoad(name, suffix); + if (segmenter != null) { + return segmenter; + } + } + return null; +} + +/// Library names paired with the symbol suffix their exports use. +Iterable<(String, String)> _candidates() sync* { + if (Platform.isWindows) { + // icu.dll since Windows 10 1903, icuuc.dll in 1703 to 1809. + yield ('icu.dll', ''); + yield ('icuuc.dll', ''); + } else if (Platform.isAndroid) { + // The NDK's public ICU, API 31+. + yield ('libicu.so', ''); + } else if (Platform.isLinux) { + // Distributions build ICU with versioned symbols such as `ubrk_open_74`, + // and only the development package installs the unversioned soname. + for (var version = 120; version >= 50; version--) { + yield ('libicuuc.so.$version', '_$version'); + yield ('libicuuc.so.$version', ''); + } + } +} + +NativeWordBoundaries? _tryLoad(String name, String suffix) { + final DynamicLibrary library; + final _Open open; + final int Function(Pointer) next; + final void Function(Pointer) close; + try { + library = DynamicLibrary.open(name); + open = library.lookupFunction<_OpenNative, _Open>('ubrk_open$suffix'); + next = library.lookupFunction), + int Function(Pointer)>('ubrk_next$suffix'); + close = library.lookupFunction), + void Function(Pointer)>('ubrk_close$suffix'); + } on ArgumentError { + return null; + } + + return (units, length) => using((arena) { + final status = arena(); + final iterator = open(_ubrkWord, nullptr, units, length, status); + // U_FAILURE: error codes are positive, warnings negative. + if (status.value > 0) { + return null; + } + final segments = []; + var start = 0; + for (var end = next(iterator); end != _ubrkDone; end = next(iterator)) { + segments.add(TextRange(start: start, end: end)); + start = end; + } + close(iterator); + return segments; + }); +} diff --git a/packages/word_segmenter/lib/src/segmenter_native.dart b/packages/word_segmenter/lib/src/segmenter_native.dart new file mode 100644 index 00000000..33a6975c --- /dev/null +++ b/packages/word_segmenter/lib/src/segmenter_native.dart @@ -0,0 +1,32 @@ +import 'dart:ffi'; +import 'dart:io'; +import 'dart:ui' show TextRange; + +import 'package:ffi/ffi.dart'; + +import 'core_foundation.dart'; +import 'icu.dart'; + +/// Segments [length] UTF-16 code units at [units]. +typedef NativeWordBoundaries = List? Function( + Pointer units, + int length, +); + +final NativeWordBoundaries? _native = + Platform.isMacOS || Platform.isIOS ? loadCoreFoundation() : loadIcu(); + +List? platformWordBoundaries(String text) { + final native = _native; + if (native == null) { + return null; + } + if (text.isEmpty) { + return const []; + } + return using((arena) { + final units = arena(text.length); + units.asTypedList(text.length).setAll(0, text.codeUnits); + return native(units, text.length); + }); +} diff --git a/packages/word_segmenter/lib/src/segmenter_unsupported.dart b/packages/word_segmenter/lib/src/segmenter_unsupported.dart new file mode 100644 index 00000000..e83dee65 --- /dev/null +++ b/packages/word_segmenter/lib/src/segmenter_unsupported.dart @@ -0,0 +1,3 @@ +import 'dart:ui' show TextRange; + +List? platformWordBoundaries(String text) => null; diff --git a/packages/word_segmenter/lib/src/segmenter_web.dart b/packages/word_segmenter/lib/src/segmenter_web.dart new file mode 100644 index 00000000..77d9e2d4 --- /dev/null +++ b/packages/word_segmenter/lib/src/segmenter_web.dart @@ -0,0 +1,43 @@ +import 'dart:js_interop'; +import 'dart:js_interop_unsafe'; +import 'dart:ui' show TextRange; + +@JS('Intl.Segmenter') +extension type _Segmenter._(JSObject _) implements JSObject { + external factory _Segmenter(JSArray locales, JSObject options); + + external JSObject segment(String input); +} + +extension type _SegmentData._(JSObject _) implements JSObject { + external int get index; + + external String get segment; +} + +@JS('Array.from') +external JSArray<_SegmentData> _arrayFrom(JSObject iterable); + +final _Segmenter? _segmenter = _createSegmenter(); + +_Segmenter? _createSegmenter() { + final intl = globalContext.getProperty('Intl'.toJS); + if (intl == null || !intl.has('Segmenter')) { + return null; + } + return _Segmenter( + JSArray(), + JSObject()..['granularity'] = 'word'.toJS, + ); +} + +List? platformWordBoundaries(String text) { + final segmenter = _segmenter; + if (segmenter == null) { + return null; + } + return [ + for (final data in _arrayFrom(segmenter.segment(text)).toDart) + TextRange(start: data.index, end: data.index + data.segment.length), + ]; +} diff --git a/packages/word_segmenter/lib/word_segmenter.dart b/packages/word_segmenter/lib/word_segmenter.dart new file mode 100644 index 00000000..c1d65622 --- /dev/null +++ b/packages/word_segmenter/lib/word_segmenter.dart @@ -0,0 +1,27 @@ +/// Word segmentation backed by the platform's own text services. +library; + +import 'dart:ui' show TextRange; + +import 'src/segmenter_unsupported.dart' + if (dart.library.js_interop) 'src/segmenter_web.dart' + if (dart.library.ffi) 'src/segmenter_native.dart'; + +/// Splits [text] at word boundaries. +/// +/// The returned segments are contiguous UTF-16 ranges that cover the whole +/// [text]: words, whitespace and punctuation each form their own segment. +/// Languages written without spaces, such as Chinese and Japanese, are split +/// with the platform's dictionaries, which Flutter's bundled ICU data leaves +/// out. +/// +/// | Platform | Backend | +/// | --- | --- | +/// | macOS, iOS | `CFStringTokenizer` | +/// | Windows | system `icu.dll` (Windows 10 1903+) | +/// | Linux | system `libicuuc` | +/// | Android | system `libicu.so` (API 31+) | +/// | Web | `Intl.Segmenter` | +/// +/// Returns null when the platform has no word segmenter available. +List? wordBoundaries(String text) => platformWordBoundaries(text); diff --git a/packages/word_segmenter/pubspec.yaml b/packages/word_segmenter/pubspec.yaml new file mode 100644 index 00000000..d5b40f9d --- /dev/null +++ b/packages/word_segmenter/pubspec.yaml @@ -0,0 +1,27 @@ +name: word_segmenter +resolution: workspace +description: Splits text at word boundaries with the platform's own text services, including dictionary-based segmentation for Chinese and Japanese. +version: 0.0.1 +homepage: https://github.com/MixinNetwork/flutter-plugins/tree/main/packages/word_segmenter + +environment: + sdk: ^3.5.0 + flutter: ">=3.2.0" + +platforms: + android: + ios: + linux: + macos: + web: + windows: + +dependencies: + flutter: + sdk: flutter + ffi: ^2.1.0 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^6.0.0 diff --git a/packages/word_segmenter/test/browser/web_segmenter_test.dart b/packages/word_segmenter/test/browser/web_segmenter_test.dart new file mode 100644 index 00000000..428f06d7 --- /dev/null +++ b/packages/word_segmenter/test/browser/web_segmenter_test.dart @@ -0,0 +1,9 @@ +@TestOn('browser') +library; + +import 'package:flutter_test/flutter_test.dart'; + +import '../word_segmenter_test.dart' as shared; + +/// Runs the shared expectations against `Intl.Segmenter`. +void main() => shared.main(); diff --git a/packages/word_segmenter/test/word_segmenter_test.dart b/packages/word_segmenter/test/word_segmenter_test.dart new file mode 100644 index 00000000..56969430 --- /dev/null +++ b/packages/word_segmenter/test/word_segmenter_test.dart @@ -0,0 +1,46 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:word_segmenter/word_segmenter.dart'; + +List segmentsOf(String text) => [ + for (final range in wordBoundaries(text)!) range.textInside(text), + ]; + +void main() { + test('segments cover the text contiguously', () { + for (final text in [ + 'Hello, world! foo-bar 1.5', + '我们今天讨论一下流式输出,然后再看。', + '👍🏽 ok 😀', + 'Flutter 桌面端 Markdown', + ]) { + final ranges = wordBoundaries(text)!; + expect(ranges.first.start, 0, reason: text); + expect(ranges.last.end, text.length, reason: text); + for (var i = 0; i < ranges.length; i++) { + expect(ranges[i].isCollapsed, isFalse, reason: text); + if (i > 0) { + expect(ranges[i].start, ranges[i - 1].end, reason: text); + } + } + } + }); + + test('splits words, spaces and punctuation', () { + expect(segmentsOf('Hello, world!'), ['Hello', ',', ' ', 'world', '!']); + }); + + test('splits Chinese into dictionary words', () { + expect( + segmentsOf('我们今天讨论一下'), + containsAllInOrder(['我们', '今天', '讨论']), + ); + }); + + test('keeps emoji sequences together', () { + expect(segmentsOf('👍🏽 ok'), ['👍🏽', ' ', 'ok']); + }); + + test('empty text has no segments', () { + expect(wordBoundaries(''), isEmpty); + }); +} diff --git a/packages/word_segmenter/tool/ci/setup_linux.ps1 b/packages/word_segmenter/tool/ci/setup_linux.ps1 new file mode 100644 index 00000000..95ec893f --- /dev/null +++ b/packages/word_segmenter/tool/ci/setup_linux.ps1 @@ -0,0 +1,11 @@ +$ErrorActionPreference = 'Stop' + +sudo apt-get update +sudo apt-get install -y ninja-build libgtk-3-dev xvfb +if ($LASTEXITCODE -ne 0) { + throw 'Installing Linux build dependencies failed.' +} + +# The example window needs an X display; later steps inherit DISPLAY. +Start-Process -FilePath Xvfb -ArgumentList ':99', '-screen', '0', '1280x1024x24' +"DISPLAY=:99" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 diff --git a/pubspec.yaml b/pubspec.yaml index b42dcb26..069aee5f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,14 +33,14 @@ workspace: - packages/ogg_opus_player/example - packages/pasteboard - packages/pasteboard/example - - packages/string_tokenizer - - packages/string_tokenizer/example - packages/ui_device - packages/ui_device/example - packages/web_qrcode - packages/web_qrcode/example - packages/win_toast - packages/win_toast/example + - packages/word_segmenter + - packages/word_segmenter/example dev_dependencies: melos: ^8.9.0