Initial commit
This commit is contained in:
commit
4f34a98e36
10
.gitignore
vendored
Executable file
10
.gitignore
vendored
Executable file
@ -0,0 +1,10 @@
|
||||
# Files and directories created by pub.
|
||||
.dart_tool/
|
||||
.packages
|
||||
|
||||
# Conventional directory for build outputs.
|
||||
build/
|
||||
|
||||
# Omit committing pubspec.lock for library packages; see
|
||||
# https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||
pubspec.lock
|
3
CHANGELOG.md
Executable file
3
CHANGELOG.md
Executable file
@ -0,0 +1,3 @@
|
||||
## 1.0.0
|
||||
|
||||
- Initial version.
|
39
README.md
Executable file
39
README.md
Executable file
@ -0,0 +1,39 @@
|
||||
<!--
|
||||
This README describes the package. If you publish this package to pub.dev,
|
||||
this README's contents appear on the landing page for your package.
|
||||
|
||||
For information about how to write a good package README, see the guide for
|
||||
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
|
||||
|
||||
For general information about developing packages, see the Dart guide for
|
||||
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
|
||||
and the Flutter guide for
|
||||
[developing packages and plugins](https://flutter.dev/developing-packages).
|
||||
-->
|
||||
|
||||
TODO: Put a short description of the package here that helps potential users
|
||||
know whether this package might be useful for them.
|
||||
|
||||
## Features
|
||||
|
||||
TODO: List what your package can do. Maybe include images, gifs, or videos.
|
||||
|
||||
## Getting started
|
||||
|
||||
TODO: List prerequisites and provide or point to information on how to
|
||||
start using the package.
|
||||
|
||||
## Usage
|
||||
|
||||
TODO: Include short and useful examples for package users. Add longer examples
|
||||
to `/example` folder.
|
||||
|
||||
```dart
|
||||
const like = 'sample';
|
||||
```
|
||||
|
||||
## Additional information
|
||||
|
||||
TODO: Tell users more about the package: where to find more information, how to
|
||||
contribute to the package, how to file issues, what response they can expect
|
||||
from the package authors, and more.
|
30
analysis_options.yaml
Executable file
30
analysis_options.yaml
Executable file
@ -0,0 +1,30 @@
|
||||
# This file configures the static analysis results for your project (errors,
|
||||
# warnings, and lints).
|
||||
#
|
||||
# This enables the 'recommended' set of lints from `package:lints`.
|
||||
# This set helps identify many issues that may lead to problems when running
|
||||
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
|
||||
# style and format.
|
||||
#
|
||||
# If you want a smaller set of lints you can change this to specify
|
||||
# 'package:lints/core.yaml'. These are just the most critical lints
|
||||
# (the recommended set includes the core lints).
|
||||
# The core lints are also what is used by pub.dev for scoring packages.
|
||||
|
||||
include: package:lints/recommended.yaml
|
||||
|
||||
# Uncomment the following section to specify additional rules.
|
||||
|
||||
# linter:
|
||||
# rules:
|
||||
# - camel_case_types
|
||||
|
||||
# analyzer:
|
||||
# exclude:
|
||||
# - path/to/excluded/files/**
|
||||
|
||||
# For more information about the core and recommended set of lints, see
|
||||
# https://dart.dev/go/core-lints
|
||||
|
||||
# For additional information about configuring this file, see
|
||||
# https://dart.dev/guides/language/analysis-options
|
82
lib/character_conversion.dart
Executable file
82
lib/character_conversion.dart
Executable file
@ -0,0 +1,82 @@
|
||||
import 'dart:math';
|
||||
|
||||
const Map<String, String> numbers = {
|
||||
'yen': '円',
|
||||
'0': '冷',
|
||||
'1': '一',
|
||||
'2': '二',
|
||||
'3': '三',
|
||||
'4': '四',
|
||||
'5': '五',
|
||||
'6': '六',
|
||||
'7': '七',
|
||||
'8': '八',
|
||||
'9': '九',
|
||||
'10': '十',
|
||||
'100': '百',
|
||||
'1000': '千',
|
||||
'10000': '万',
|
||||
'10^8': '億',
|
||||
'10^12': '兆',
|
||||
'10^16': '京',
|
||||
'10^20': '垓',
|
||||
'10^24': '𥝱',
|
||||
'10^28': '穣',
|
||||
'10^32': '溝',
|
||||
'10^36': '澗',
|
||||
'10^40': '正',
|
||||
'10^44': '載',
|
||||
'10^48': '極',
|
||||
};
|
||||
|
||||
const Map<String, String> formalNumbers = {
|
||||
'yen': '圓',
|
||||
'0': '冷',
|
||||
'1': '壱',
|
||||
'2': '弐',
|
||||
'3': '参',
|
||||
'4': '肆',
|
||||
'5': '伍',
|
||||
'6': '陸',
|
||||
'7': '漆',
|
||||
'8': '捌',
|
||||
'9': '玖',
|
||||
'10': '拾',
|
||||
'100': '陌',
|
||||
'1000': '阡',
|
||||
'10000': '萬',
|
||||
};
|
||||
|
||||
String numberToKanji(
|
||||
int number, {
|
||||
bool placeValue = false,
|
||||
bool formal = false,
|
||||
bool yen = false,
|
||||
}) {
|
||||
if (placeValue) {
|
||||
return number
|
||||
.toString()
|
||||
.split('')
|
||||
.map((e) => e == '0' ? '〇' : numbers[e]!)
|
||||
.join() +
|
||||
(yen ? numbers['yen']! : '');
|
||||
} else {
|
||||
final Map<String, String> numberSet = formal ? numbers : formalNumbers;
|
||||
// int i = number;
|
||||
// while(i )
|
||||
}
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
enum RomanizationSystem { hepburn, nippon, passport }
|
||||
|
||||
// FullwidthChar
|
||||
// FullwidthNum
|
||||
// Hiragana
|
||||
// Katakana
|
||||
// Halfwidth katakana
|
||||
|
||||
|
||||
void main(List<String> args) {
|
||||
print(numberToKanji(2012, placeValue: true));
|
||||
}
|
114
lib/iconv/character_set_conversion.dart
Executable file
114
lib/iconv/character_set_conversion.dart
Executable file
@ -0,0 +1,114 @@
|
||||
// KangXi to Unified CJK
|
||||
// Unified CJK to KangXi
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'character_sets/jisx0208.dart';
|
||||
import 'datatypes.dart';
|
||||
|
||||
class ConverterException implements Exception {
|
||||
String cause;
|
||||
ConverterException(this.cause);
|
||||
}
|
||||
|
||||
/// raw 7 or 8 bit encoding?
|
||||
class JSIX0201 {}
|
||||
|
||||
/// Character sets that supports this:
|
||||
/// Shift JIS ("SJIS")
|
||||
/// ISO-2022-JP ("JIS")
|
||||
/// EUC-JP ("UJIS")
|
||||
///
|
||||
/// Takes a unicode character code and converts it to its JSIX0208 equivalent
|
||||
/// If no such symbol is found, it will return a null value.
|
||||
class JSIX0208Decoder extends Converter<int, int?> {
|
||||
/// See jisx0208_mbtowc(...) at
|
||||
/// https://github.com/xbmc/libiconv/blob/master/lib/jisx0208.h
|
||||
static int? decode16BitCharacter(int character) {
|
||||
int c1 = character >> 8;
|
||||
int c2 = character & 0x00FF;
|
||||
if (!((c1.between(0x21, 0x28) || c1.between(0x30, 0x74)) &&
|
||||
c2.between(0x21, 0x7e))) {
|
||||
throw ConverterException("Illegal sequence");
|
||||
}
|
||||
|
||||
int i = 94 * (c1 - 0x21) + (c2 - 0x21);
|
||||
int? wc;
|
||||
if (i < 690) {
|
||||
wc = jisx0208_2uni_page21[i];
|
||||
} else if (i < 7808) {
|
||||
wc = jisx0208_2uni_page30[i - 1410];
|
||||
}
|
||||
return wc;
|
||||
}
|
||||
|
||||
@override
|
||||
convert(int input) => decode16BitCharacter(input);
|
||||
}
|
||||
|
||||
class JSIX0208Encoder extends Converter<int, int?> {
|
||||
/// See jisx0208_wctomb(...) at
|
||||
/// https://github.com/xbmc/libiconv/blob/master/lib/jisx0208.h
|
||||
int? encode16BitCharacter(int character) {
|
||||
S16? summary;
|
||||
if (character.betweenTo(0x0000, 0x0100)) {
|
||||
summary = jisx0208_uni2indx_page00[(character >> 4)];
|
||||
} else if (character.betweenTo(0x0300, 0x0460)) {
|
||||
summary = jisx0208_uni2indx_page03[(character >> 4) - 0x030];
|
||||
} else if (character.betweenTo(0x2000, 0x2320)) {
|
||||
summary = jisx0208_uni2indx_page20[(character >> 4) - 0x200];
|
||||
} else if (character.betweenTo(0x2500, 0x2670)) {
|
||||
summary = jisx0208_uni2indx_page25[(character >> 4) - 0x250];
|
||||
} else if (character.betweenTo(0x3000, 0x3100)) {
|
||||
summary = jisx0208_uni2indx_page30[(character >> 4) - 0x300];
|
||||
} else if (character.betweenTo(0x4e00, 0x9fb0)) {
|
||||
summary = jisx0208_uni2indx_page4e[(character >> 4) - 0x4e0];
|
||||
} else if (character.betweenTo(0xff00, 0xfff0)) {
|
||||
summary = jisx0208_uni2indx_pageff[(character >> 4) - 0xff0];
|
||||
}
|
||||
|
||||
final int i = (1 << (character & 0x0f)).asShort;
|
||||
if (summary == null || ((summary.used & i) == 0)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int used = summary.used;
|
||||
/* Keep in 'used' only the bits 0..i-1. */
|
||||
used &= i - 1;
|
||||
/* Add 'summary.index' and the number of bits set in 'used'. */
|
||||
used = (used & 0x5555) + ((used & 0xaaaa) >> 1);
|
||||
used = (used & 0x3333) + ((used & 0xcccc) >> 2);
|
||||
used = (used & 0x0f0f) + ((used & 0xf0f0) >> 4);
|
||||
used = (used & 0x00ff) + (used >> 8);
|
||||
return jisx0208_2charset[summary.index + used];
|
||||
}
|
||||
|
||||
@override
|
||||
int? convert(int input) => encode16BitCharacter(input);
|
||||
}
|
||||
|
||||
/// EUC-JP
|
||||
/// ISO-2022-JP-1
|
||||
class JSIX0212 {}
|
||||
|
||||
/// Shift_JIS-2004
|
||||
/// ISO-2022-JP-2004
|
||||
/// EUC-JIS-2004
|
||||
class JSIX0213 {}
|
||||
|
||||
|
||||
// to_utf8
|
||||
// from_utf8
|
||||
// from_code
|
||||
// to_code
|
||||
|
||||
// X
|
||||
|
||||
// JSX0208
|
||||
// JSX0211
|
||||
// JSX0212
|
||||
// JSX0213
|
||||
// EUC_JP
|
||||
// JIS
|
||||
// SJIS
|
||||
|
0
lib/iconv/character_sets/jisx0201.dart
Executable file
0
lib/iconv/character_sets/jisx0201.dart
Executable file
2333
lib/iconv/character_sets/jisx0208.dart
Executable file
2333
lib/iconv/character_sets/jisx0208.dart
Executable file
File diff suppressed because it is too large
Load Diff
169
lib/iconv/codecs.dart
Executable file
169
lib/iconv/codecs.dart
Executable file
@ -0,0 +1,169 @@
|
||||
// https://en.wikipedia.org/wiki/JIS_encoding
|
||||
// https://en.wikipedia.org/wiki/Japanese_Industrial_Standards
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'datatypes.dart';
|
||||
import 'character_set_conversion.dart';
|
||||
|
||||
/// ISO-2002-JP (Usually abbreviated "JIS")
|
||||
/// Encodes, decodes: JIS X 0202
|
||||
///
|
||||
///
|
||||
// class ISO2002JP extends Encoding {}
|
||||
|
||||
enum ShiftJISCharacterSet {
|
||||
jisx0201,
|
||||
jisx0208,
|
||||
lundeRange,
|
||||
}
|
||||
|
||||
/// Shift JIS (Usually abbreviated "SJIS")
|
||||
/// Encodes, decodes: JIS X 0208
|
||||
///
|
||||
/// https://en.wikipedia.org/wiki/Shift_JIS
|
||||
class ShiftJIS extends Encoding {
|
||||
int? decodeWithJsix0201(int char) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// Decode 16 bit character
|
||||
int? decodeWithJsix0208(int char) {
|
||||
int s1 = char >> 8;
|
||||
int s2 = char & 0x00FF;
|
||||
|
||||
if (!((s1.between(0x81, 0x9f) || s1.between(0xe0, 0xea)) &&
|
||||
(s1.between(0x40, 0x7e) || s1.between(0x80, 0xfc)))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int t1 = (s1 < 0xe0 ? s1 - 0x81 : s1 - 0xc1);
|
||||
int t2 = (s2 < 0x80 ? s2 - 0x40 : s2 - 0x41);
|
||||
|
||||
int ffoo = 2 * t1 + (t2 < 0x5e ? 0 : 1) + 0x21;
|
||||
int ooff = (t2 < 0x5e ? t2 : t2 - 0x5e) + 0x21;
|
||||
int ffff = (ffoo << 8) + ooff;
|
||||
|
||||
return JSIX0208Decoder().convert(ffff);
|
||||
}
|
||||
|
||||
int? decodeWithLundeRange(int char) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
int? encodeWithJisx0201(int char) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
int? encodeWithJisx0208(int char) {
|
||||
final jsixEncoded = JSIX0208Encoder().convert(char);
|
||||
|
||||
if (jsixEncoded == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int c1 = jsixEncoded >> 8;
|
||||
int c2 = jsixEncoded & 0x00FF;
|
||||
|
||||
if (!(c1.between(0x21, 0x74) && c2.between(0x21, 0x7e))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int t1 = (c1 - 0x21) >> 1;
|
||||
int t2 = ((((c1 - 0x21) & 1) != 0) ? 0x5e : 0) + (c2 - 0x21);
|
||||
|
||||
int ffoo = (t1 < 0x1f ? t1 + 0x81 : t1 + 0xc1);
|
||||
int ooff = (t2 < 0x3f ? t2 + 0x40 : t2 + 0x41);
|
||||
|
||||
return (ffoo << 8) + ooff;
|
||||
}
|
||||
|
||||
int? encodeWithLundeRange(int char) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
List<int> encode(
|
||||
String input, {
|
||||
ShiftJISCharacterSet? forceCharacterSet,
|
||||
bool ignoreUnknownCharacters = false,
|
||||
}) {
|
||||
List<int> result = [];
|
||||
List<int> toEncode = input.codeUnits;
|
||||
for (int i = 0; i < toEncode.length; i++) {
|
||||
final int charcode = toEncode[i];
|
||||
final int? encodedChar = encodeWithJisx0208(charcode);
|
||||
if (encodedChar == null) {
|
||||
if (ignoreUnknownCharacters) {
|
||||
continue;
|
||||
} else {
|
||||
throw ConverterException(
|
||||
"Unable to convert character '${String.fromCharCode(charcode)}' at index [$i]",
|
||||
);
|
||||
}
|
||||
}
|
||||
result.add(encodedChar);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
String decode(
|
||||
List<int> encoded, {
|
||||
ShiftJISCharacterSet? forceCharacterSet,
|
||||
bool ignoreUnknownCharacters = false,
|
||||
}) {
|
||||
List<int> result = [];
|
||||
for (int i = 0; i < encoded.length; i++) {
|
||||
final int encodedChar = encoded[i];
|
||||
final int? translatedChar = decodeWithJsix0208(encodedChar);
|
||||
if (translatedChar == null) {
|
||||
if (ignoreUnknownCharacters) {
|
||||
continue;
|
||||
} else {
|
||||
throw ConverterException(
|
||||
"Unknown character: ${encodedChar.hex} at index [$i]",
|
||||
);
|
||||
}
|
||||
}
|
||||
result.add(translatedChar);
|
||||
}
|
||||
return String.fromCharCodes(result);
|
||||
}
|
||||
|
||||
@override
|
||||
Converter<String, List<int>> get encoder => throw UnimplementedError();
|
||||
|
||||
@override
|
||||
Converter<List<int>, String> get decoder => throw UnimplementedError();
|
||||
|
||||
@override
|
||||
String get name => "Shift JIS";
|
||||
}
|
||||
|
||||
/// EUC-JP (Usually abbreviated "UJIS")
|
||||
/// Unixized JIS
|
||||
/// Encodes, decodes: JIS X 0201, JIS X 0208, JIS X 0212
|
||||
///
|
||||
/// https://en.wikipedia.org/wiki/Extended_Unix_Code#EUC-JP=
|
||||
class EUCJP {}
|
||||
|
||||
void main() {
|
||||
final file = File("test.sjis.txt");
|
||||
final ByteData data = ByteData.sublistView(file.readAsBytesSync());
|
||||
final List<int> characterCodes = [
|
||||
for (int i = 0; i < ((data.lengthInBytes) / 2).floor(); i++)
|
||||
data.getUint16(i * 2)
|
||||
];
|
||||
print(characterCodes);
|
||||
|
||||
// print(ShiftJIS().decode(characterCodes));
|
||||
|
||||
// print(JSIX0208Encoder().encode16BitCharacter('あ'.codeUnitAt(0)));
|
||||
// print(JSIX0208Encoder().encode16BitCharacter('幹'.codeUnitAt(0)));
|
||||
final x = ShiftJIS().encode("この文章は読めるかな?");
|
||||
print(data.buffer.asUint8List());
|
||||
File("test.sjis2.txt").writeAsBytesSync(Uint16List.fromList(x));
|
||||
}
|
26
lib/iconv/datatypes.dart
Executable file
26
lib/iconv/datatypes.dart
Executable file
@ -0,0 +1,26 @@
|
||||
class S16 {
|
||||
final int index;
|
||||
final int used;
|
||||
|
||||
const S16(this.index, this.used);
|
||||
}
|
||||
|
||||
|
||||
/// Some tools that come in handy when working with bits and bytes.
|
||||
extension CharacterSetTools on int {
|
||||
/// Casting to unsigned short would be the same as removing
|
||||
/// all bytes except the 4 last.
|
||||
int get asShort => this & 0xffff;
|
||||
|
||||
/// Ease of printing for debugging purposes.
|
||||
String get hex => "0x${toRadixString(16)}";
|
||||
|
||||
/// Mask and bitshift
|
||||
// int bitrange(int a, int b) => this >> a;
|
||||
|
||||
/// a <= this <= b
|
||||
bool between(int a, int b) => a <= this && this <= b;
|
||||
|
||||
/// a <= this < b
|
||||
bool betweenTo(int a, int b) => a <= this && this < b;
|
||||
}
|
11
lib/japanese_tools.dart
Executable file
11
lib/japanese_tools.dart
Executable file
@ -0,0 +1,11 @@
|
||||
/// Support for doing something awesome.
|
||||
///
|
||||
/// More dartdocs go here.
|
||||
library japanese_tools;
|
||||
|
||||
export 'iconv/character_set_conversion.dart';
|
||||
export 'iconv/codecs.dart';
|
||||
export 'character_conversion.dart';
|
||||
export 'radkfile.dart';
|
||||
export 'regex.dart';
|
||||
export 'unit_conversion.dart';
|
0
lib/radkfile.dart
Executable file
0
lib/radkfile.dart
Executable file
45
lib/regex.dart
Executable file
45
lib/regex.dart
Executable file
@ -0,0 +1,45 @@
|
||||
|
||||
/// The string version of a regex that will match any Unified CJK Character.
|
||||
/// This includes the ranges (), ()
|
||||
///
|
||||
/// See https://www.regular-expressions.info/unicode.html
|
||||
///
|
||||
/// Remember to turn on the unicode flag when making a new RegExp.
|
||||
const String rawKanjiRegex = r'\p{Script=Hani}';
|
||||
|
||||
/// The string version of a regex that will match any katakana.
|
||||
/// This includes the ranges (), ()
|
||||
///
|
||||
/// See https://www.regular-expressions.info/unicode.html
|
||||
///
|
||||
/// Remember to turn on the unicode flag when making a new RegExp.
|
||||
const String rawKatakanaRegex = r'\p{Script=Katakana}';
|
||||
|
||||
/// The string version of a regex that will match any hiragana.
|
||||
/// This includes the ranges (), ()
|
||||
///
|
||||
/// See https://www.regular-expressions.info/unicode.html
|
||||
///
|
||||
/// Remember to turn on the unicode flag when making a new RegExp.
|
||||
const String rawHiraganaRegex = r'\p{Script=Hiragana}';
|
||||
|
||||
|
||||
final RegExp kanjiRegex = RegExp(rawKanjiRegex, unicode: true);
|
||||
final RegExp katakanaRegex = RegExp(rawKatakanaRegex, unicode: true);
|
||||
final RegExp hiraganaRegex = RegExp(rawHiraganaRegex, unicode: true);
|
||||
|
||||
// symbols
|
||||
|
||||
|
||||
|
||||
|
||||
//is
|
||||
//has
|
||||
|
||||
// X
|
||||
|
||||
// kana
|
||||
// katakana
|
||||
// hiragana
|
||||
// japanese
|
||||
// kanji
|
303
lib/unit_conversion.dart
Executable file
303
lib/unit_conversion.dart
Executable file
@ -0,0 +1,303 @@
|
||||
import 'dart:core';
|
||||
// extension on Date
|
||||
// Year 平成 昭和
|
||||
// Full date
|
||||
|
||||
|
||||
// Run in console on http://www.kumamotokokufu-h.ed.jp/kumamoto/bungaku/nengoui.html
|
||||
// Array.from(document.querySelectorAll('table')[1].querySelectorAll('tr')).slice(1).map(row => `DateTime(${row.children[3 + (row.children.length == 7)].innerHTML.replace(/~.*/, '')}, ${row.children[4 + (row.children.length == 7)].innerHTML.replace('/', ', ')}): '${row.children[2 + (row.children.length == 7)].innerHTML}'`).join('\n')
|
||||
|
||||
Map<DateTime, String> periodsBeforeNanbokuchou = {
|
||||
DateTime(645, 6, 19): '大化',
|
||||
DateTime(650, 2, 15): '白雉',
|
||||
DateTime(686, 7, 20): '朱鳥',
|
||||
DateTime(701, 3, 21): '大宝',
|
||||
DateTime(704, 5, 10): '慶雲',
|
||||
DateTime(708, 1, 11): '和銅',
|
||||
DateTime(715, 9, 2): '霊亀',
|
||||
DateTime(717, 11, 17): '養老',
|
||||
DateTime(724, 2, 4): '神亀',
|
||||
DateTime(729, 8, 5): '天平',
|
||||
DateTime(749, 4, 14): '天平感宝',
|
||||
DateTime(749, 7, 2): '天平勝宝',
|
||||
DateTime(757, 8, 18): '天平宝字',
|
||||
DateTime(765, 1, 7): '天平神護',
|
||||
DateTime(767, 8, 16): '神護景雲',
|
||||
DateTime(770, 10, 1): '宝亀',
|
||||
DateTime(781, 1, 1): '天応',
|
||||
DateTime(782, 8, 19): '延暦',
|
||||
DateTime(806, 5, 18): '大同',
|
||||
DateTime(810, 9, 19): '弘仁',
|
||||
DateTime(824, 1, 5): '天長',
|
||||
DateTime(834, 1, 3): '承和',
|
||||
DateTime(848, 6, 13): '嘉祥',
|
||||
DateTime(851, 4, 28): '仁寿',
|
||||
DateTime(854, 11, 30): '斎衡',
|
||||
DateTime(857, 2, 21): '天安',
|
||||
DateTime(859, 4, 15): '貞観',
|
||||
DateTime(877, 4, 16): '元慶',
|
||||
DateTime(885, 2, 21): '仁和',
|
||||
DateTime(889, 4, 27): '寛平',
|
||||
DateTime(898, 4, 26): '昌泰',
|
||||
DateTime(901, 7, 15): '延喜',
|
||||
DateTime(923, 4, 11): '延長',
|
||||
DateTime(931, 4, 26): '承平',
|
||||
DateTime(938, 5, 22): '天慶',
|
||||
DateTime(947, 4, 22): '天暦',
|
||||
DateTime(957, 10, 27): '天徳',
|
||||
DateTime(961, 2, 16): '応和',
|
||||
DateTime(964, 7, 10): '康保',
|
||||
DateTime(968, 8, 13): '安和',
|
||||
DateTime(970, 3, 25): '天禄',
|
||||
DateTime(973, 12, 20): '天延',
|
||||
DateTime(976, 7, 13): '貞元',
|
||||
DateTime(978, 11, 29): '天元',
|
||||
DateTime(983, 4, 15): '永観',
|
||||
DateTime(985, 4, 27): '寛和',
|
||||
DateTime(987, 4, 5): '永延',
|
||||
DateTime(989, 8, 8): '永祚',
|
||||
DateTime(990, 11, 7): '正暦',
|
||||
DateTime(995, 2, 22): '長徳',
|
||||
DateTime(999, 1, 13): '長保',
|
||||
DateTime(1004, 7, 20): '寛弘',
|
||||
DateTime(1012, 12, 25): '長和',
|
||||
DateTime(1017, 4, 23): '寛仁',
|
||||
DateTime(1021, 2, 2): '治安',
|
||||
DateTime(1024, 7, 13): '万寿',
|
||||
DateTime(1028, 7, 25): '長元',
|
||||
DateTime(1037, 4, 21): '長暦',
|
||||
DateTime(1040, 11, 10): '長久',
|
||||
DateTime(1044, 11, 24): '寛徳',
|
||||
DateTime(1046, 4, 14): '永承',
|
||||
DateTime(1053, 1, 11): '天喜',
|
||||
DateTime(1058, 8, 29): '康平',
|
||||
DateTime(1065, 8, 2): '治暦',
|
||||
DateTime(1069, 4, 13): '延久',
|
||||
DateTime(1074, 8, 23): '承保',
|
||||
DateTime(1077, 11, 17): '承暦',
|
||||
DateTime(1081, 2, 10): '永保',
|
||||
DateTime(1084, 2, 7): '応徳',
|
||||
DateTime(1087, 4, 7): '寛治',
|
||||
DateTime(1094, 12, 15): '嘉保',
|
||||
DateTime(1096, 12, 17): '永長',
|
||||
DateTime(1097, 11, 21): '承徳',
|
||||
DateTime(1099, 8, 28): '康和',
|
||||
DateTime(1104, 2, 10): '長治',
|
||||
DateTime(1106, 4, 9): '嘉承',
|
||||
DateTime(1108, 8, 3): '天仁',
|
||||
DateTime(1110, 7, 13): '天永',
|
||||
DateTime(1113, 7, 13): '永久',
|
||||
DateTime(1118, 4, 3): '元永',
|
||||
DateTime(1120, 4, 10): '保安',
|
||||
DateTime(1124, 4, 3): '天治',
|
||||
DateTime(1126, 1, 22): '大治',
|
||||
DateTime(1131, 1, 29): '天承',
|
||||
DateTime(1132, 8, 11): '長承',
|
||||
DateTime(1135, 4, 27): '保延',
|
||||
DateTime(1141, 7, 10): '永治',
|
||||
DateTime(1142, 4, 28): '康治',
|
||||
DateTime(1144, 2, 23): '天養',
|
||||
DateTime(1145, 7, 22): '久安',
|
||||
DateTime(1151, 1, 26): '仁平',
|
||||
DateTime(1154, 10, 28): '久寿',
|
||||
DateTime(1156, 4, 27): '保元',
|
||||
DateTime(1159, 4, 20): '平治',
|
||||
DateTime(1160, 1, 10): '永暦',
|
||||
DateTime(1161, 9, 4): '応保',
|
||||
DateTime(1163, 3, 29): '長寛',
|
||||
DateTime(1165, 6, 5): '永万',
|
||||
DateTime(1166, 8, 27): '仁安',
|
||||
DateTime(1169, 4, 8): '嘉応',
|
||||
DateTime(1171, 4, 21): '承安',
|
||||
DateTime(1175, 7, 28): '安元',
|
||||
DateTime(1177, 8, 4): '治承',
|
||||
DateTime(1181, 7, 14): '養和',
|
||||
DateTime(1182, 5, 27): '寿永',
|
||||
DateTime(1184, 4, 16): '元暦',
|
||||
DateTime(1185, 8, 14): '文治',
|
||||
DateTime(1190, 4, 11): '建久',
|
||||
DateTime(1199, 4, 27): '正治',
|
||||
DateTime(1201, 2, 13): '建仁',
|
||||
DateTime(1204, 2, 20): '元久',
|
||||
DateTime(1206, 4, 27): '建永',
|
||||
DateTime(1207, 10, 25): '承元',
|
||||
DateTime(1211, 3, 9): '建暦',
|
||||
DateTime(1213, 12, 6): '建保',
|
||||
DateTime(1219, 4, 12): '承久',
|
||||
DateTime(1222, 4, 13): '貞応',
|
||||
DateTime(1224, 11, 20): '元仁',
|
||||
DateTime(1225, 4, 20): '嘉禄',
|
||||
DateTime(1227, 12, 10): '安貞',
|
||||
DateTime(1229, 3, 5): '寛喜',
|
||||
DateTime(1232, 4, 2): '貞永',
|
||||
DateTime(1233, 4, 15): '天福',
|
||||
DateTime(1234, 11, 5): '文暦',
|
||||
DateTime(1235, 9, 19): '嘉禎',
|
||||
DateTime(1238, 11, 23): '暦仁',
|
||||
DateTime(1239, 2, 7): '延応',
|
||||
DateTime(1240, 7, 16): '仁治',
|
||||
DateTime(1243, 2, 26): '寛元',
|
||||
DateTime(1247, 2, 28): '宝治',
|
||||
DateTime(1249, 3, 18): '建長',
|
||||
DateTime(1256, 10, 5): '康元',
|
||||
DateTime(1257, 3, 14): '正嘉',
|
||||
DateTime(1259, 3, 26): '正元',
|
||||
DateTime(1260, 4, 13): '文応',
|
||||
DateTime(1261, 2, 20): '弘長',
|
||||
DateTime(1264, 2, 28): '文永',
|
||||
DateTime(1275, 4, 25): '建治',
|
||||
DateTime(1278, 2, 29): '弘安',
|
||||
DateTime(1288, 4, 28): '正応',
|
||||
DateTime(1293, 8, 5): '永仁',
|
||||
DateTime(1299, 4, 25): '正安',
|
||||
DateTime(1302, 11, 21): '乾元',
|
||||
DateTime(1303, 8, 5): '嘉元',
|
||||
DateTime(1306, 12, 14): '徳治',
|
||||
DateTime(1308, 10, 9): '延慶',
|
||||
DateTime(1311, 4, 28): '応長',
|
||||
DateTime(1312, 3, 20): '正和',
|
||||
DateTime(1317, 2, 3): '文保',
|
||||
DateTime(1319, 4, 28): '元応',
|
||||
DateTime(1321, 2, 23): '元亨',
|
||||
DateTime(1324, 12, 9): '正中',
|
||||
DateTime(1326, 4, 26): '嘉暦',
|
||||
};
|
||||
|
||||
final Map<DateTime, String> periodsNanbokuchouNorth = {
|
||||
DateTime(1329, 8, 29): '元徳',
|
||||
DateTime(1332, 4, 28): '正慶',
|
||||
DateTime(1334, 1, 29): '建武',
|
||||
DateTime(1338, 8, 28): '暦応',
|
||||
DateTime(1342, 4, 27): '康永',
|
||||
DateTime(1345, 10, 21): '貞和',
|
||||
DateTime(1350, 2, 27): '観応',
|
||||
DateTime(1352, 9, 27): '文和',
|
||||
DateTime(1356, 3, 28): '延文',
|
||||
DateTime(1361, 3, 29): '康安',
|
||||
DateTime(1362, 9, 23): '貞治',
|
||||
DateTime(1368, 2, 18): '応安',
|
||||
DateTime(1375, 2, 27): '永和',
|
||||
DateTime(1379, 3, 22): '康暦',
|
||||
DateTime(1381, 2, 24): '永徳',
|
||||
DateTime(1384, 2, 27): '至徳',
|
||||
DateTime(1387, 8, 23): '嘉慶',
|
||||
DateTime(1389, 2, 9): '康応',
|
||||
DateTime(1390, 3, 26): '明徳',
|
||||
};
|
||||
|
||||
final Map<DateTime, String> periodsNanbokuchouSouth = {
|
||||
DateTime(1329, 8, 29): '元徳',
|
||||
DateTime(1331, 8, 9): '元弘',
|
||||
DateTime(1334, 1, 29): '建武',
|
||||
DateTime(1336, 2, 29): '延元',
|
||||
DateTime(1340, 4, 28): '興国',
|
||||
DateTime(1346, 12, 8): '正平',
|
||||
DateTime(1370, 7, 24): '建徳',
|
||||
DateTime(1372, 4, 4): '文中',
|
||||
DateTime(1375, 5, 27): '天授',
|
||||
DateTime(1381, 2, 10): '弘和',
|
||||
DateTime(1384, 4, 28): '元中',
|
||||
};
|
||||
|
||||
final Map<DateTime, String> periodsAfterNanbokuchou = {
|
||||
// DateTime(1392, ): '室町時代',
|
||||
DateTime(1394, 7, 5): '応永',
|
||||
DateTime(1428, 4, 27): '正長',
|
||||
DateTime(1429, 9, 5): '永享',
|
||||
DateTime(1441, 2, 17): '嘉吉',
|
||||
DateTime(1444, 2, 5): '文安',
|
||||
DateTime(1449, 7, 28): '宝徳',
|
||||
DateTime(1452, 7, 25): '享徳',
|
||||
DateTime(1455, 7, 25): '康正',
|
||||
DateTime(1457, 9, 28): '長禄',
|
||||
DateTime(1460, 12, 21): '寛正',
|
||||
DateTime(1466, 2, 28): '文正',
|
||||
DateTime(1467, 3, 5): '応仁',
|
||||
DateTime(1469, 4, 28): '文明',
|
||||
DateTime(1487, 7, 20): '長享',
|
||||
DateTime(1489, 8, 21): '延徳',
|
||||
DateTime(1492, 7, 19): '明応',
|
||||
DateTime(1501, 2, 29): '文亀',
|
||||
DateTime(1504, 2, 30): '永正',
|
||||
DateTime(1521, 8, 23): '大永',
|
||||
DateTime(1528, 8, 20): '享禄',
|
||||
DateTime(1532, 7, 29): '天文',
|
||||
DateTime(1555, 10, 23): '弘治',
|
||||
DateTime(1558, 2, 28): '永禄',
|
||||
DateTime(1570, 4, 23): '元亀',
|
||||
DateTime(1573, 7, 28): '天正',
|
||||
DateTime(1592, 12, 8): '文禄',
|
||||
DateTime(1596, 10, 27): '慶長',
|
||||
DateTime(1615, 7, 13): '元和',
|
||||
DateTime(1624, 2, 30): '寛永',
|
||||
DateTime(1644, 12, 16): '正保',
|
||||
DateTime(1648, 2, 15): '慶安',
|
||||
DateTime(1652, 9, 18): '承応',
|
||||
DateTime(1655, 4, 13): '明暦',
|
||||
DateTime(1658, 7, 23): '万治',
|
||||
DateTime(1661, 4, 25): '寛文',
|
||||
DateTime(1673, 9, 21): '延宝',
|
||||
DateTime(1681, 9, 29): '天和',
|
||||
DateTime(1684, 2, 21): '貞享',
|
||||
DateTime(1688, 9, 30): '元禄',
|
||||
DateTime(1704, 3, 13): '宝永',
|
||||
DateTime(1711, 4, 25): '正徳',
|
||||
DateTime(1716, 6, 22): '享保',
|
||||
DateTime(1736, 4, 28): '元文',
|
||||
DateTime(1741, 2, 27): '寛保',
|
||||
DateTime(1744, 2, 21): '延享',
|
||||
DateTime(1748, 7, 12): '寛延',
|
||||
DateTime(1751, 10, 27): '宝暦',
|
||||
DateTime(1764, 6, 2): '明和',
|
||||
DateTime(1772, 11, 16): '安永',
|
||||
DateTime(1781, 4, 2): '天明',
|
||||
DateTime(1789, 1, 25): '寛政',
|
||||
DateTime(1801, 2, 5): '享和',
|
||||
DateTime(1804, 2, 11): '文化',
|
||||
DateTime(1818, 4, 22): '文政',
|
||||
DateTime(1830, 12, 10): '天保',
|
||||
DateTime(1844, 12, 2): '弘化',
|
||||
DateTime(1848, 2, 28): '嘉永',
|
||||
DateTime(1854, 11, 27): '安政',
|
||||
DateTime(1860, 3, 18): '万延',
|
||||
DateTime(1861, 2, 19): '文久',
|
||||
DateTime(1864, 2, 20): '元治',
|
||||
DateTime(1865, 4, 7): '慶応',
|
||||
DateTime(1868, 9, 8): '明治',
|
||||
DateTime(1912, 7, 30): '大正',
|
||||
DateTime(1926, 12, 25): '昭和',
|
||||
DateTime(1989, 1, 8): '平成'
|
||||
};
|
||||
|
||||
|
||||
|
||||
extension on DateTime {
|
||||
String get japaneseEra {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// Note: In the years between 1336 and 1392, Japan was split in two
|
||||
/// because of an ongoing conflict. As a result, Japan has two timelines
|
||||
/// during these years. Unless you turn off [nanbokuchouPeriodUsesNorth],
|
||||
/// function will give you the timeline from the northern part of Japan
|
||||
/// as a default.
|
||||
///
|
||||
/// See more info here:
|
||||
/// - https://en.wikipedia.org/wiki/Nanboku-ch%C5%8D_period
|
||||
/// - http://www.kumamotokokufu-h.ed.jp/kumamoto/bungaku/nengoui.html
|
||||
String japaneseYear({bool nanbokuchouPeriodUsesNorth = true}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
String get japaneseWeekday => [
|
||||
'月',
|
||||
'火',
|
||||
'水',
|
||||
'木',
|
||||
'金',
|
||||
'土',
|
||||
'日',
|
||||
][weekday - 1];
|
||||
|
||||
String japaneseDate({bool showWeekday = false}) => '$month月$day日' + (showWeekday ? '($japaneseWeekday)' : '');
|
||||
}
|
15
pubspec.yaml
Executable file
15
pubspec.yaml
Executable file
@ -0,0 +1,15 @@
|
||||
name: japanese_tools
|
||||
description: A starting point for Dart libraries or applications.
|
||||
version: 1.0.0
|
||||
# homepage: https://www.example.com
|
||||
|
||||
environment:
|
||||
sdk: '>=2.16.1 <3.0.0'
|
||||
|
||||
|
||||
# dependencies:
|
||||
# path: ^1.8.0
|
||||
|
||||
dev_dependencies:
|
||||
lints: ^1.0.0
|
||||
test: ^1.16.0
|
1
test.sjis.txt
Executable file
1
test.sjis.txt
Executable file
@ -0,0 +1 @@
|
||||
この文章は読めるかな?
|
1
test.sjis2.txt
Executable file
1
test.sjis2.txt
Executable file
@ -0,0 +1 @@
|
||||
アフカヘヘヌ゚鬩ネH
|
1
test.txt
Executable file
1
test.txt
Executable file
@ -0,0 +1 @@
|
||||
この文章は読めるかな?
|
Reference in New Issue
Block a user