Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unified/shortname mapping tables #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 32 additions & 37 deletions build/build_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@

$maps = array();

$maps['names'] = make_names_map($catalog);
$maps['names'] = make_mapping($catalog, 'unified', 'name');
$maps['kaomoji'] = get_all_kaomoji($catalog);

#fprintf(STDERR, "fix Geta Mark () '〓' (U+3013)\n");
#$catalog = fix_geta_mark($catalog);

$maps["unified_to_docomo"] = make_mapping($catalog, 'docomo');
$maps["unified_to_kddi"] = make_mapping($catalog, 'au');
$maps["unified_to_softbank"] = make_mapping($catalog, 'softbank');
$maps["unified_to_google"] = make_mapping($catalog, 'google');
$maps["unified_to_docomo"] = make_mapping($catalog, 'unified', 'docomo');
$maps["unified_to_kddi"] = make_mapping($catalog, 'unified', 'au');
$maps["unified_to_softbank"] = make_mapping($catalog, 'unified', 'softbank');
$maps["unified_to_google"] = make_mapping($catalog, 'unified', 'google');
$maps["unified_to_shortname"] = make_mapping($catalog, 'unified', 'short_name');

$maps["docomo_to_unified"] = make_mapping_flip($catalog, 'docomo');
$maps["kddi_to_unified"] = make_mapping_flip($catalog, 'au');
$maps["softbank_to_unified"] = make_mapping_flip($catalog, 'softbank');
$maps["google_to_unified"] = make_mapping_flip($catalog, 'google');
$maps["docomo_to_unified"] = make_mapping($catalog, 'docomo', 'unified');
$maps["kddi_to_unified"] = make_mapping($catalog, 'au', 'unified');
$maps["softbank_to_unified"] = make_mapping($catalog, 'softbank', 'unified');
$maps["google_to_unified"] = make_mapping($catalog, 'google', 'unified');
$maps["shortname_to_unified"] = make_mapping($catalog, 'short_names', 'unified');

$maps["unified_to_html"] = make_html_map($catalog);

Expand Down Expand Up @@ -97,19 +99,6 @@ function get_all_kaomoji($mapping){
return array_keys($arr);
}

function make_names_map($map){

$out = array();
foreach ($map as $row){

$bytes = unicode_bytes($row['unified']);

$out[$bytes] = $row['name'];
}

return $out;
}

function make_html_map($map){

$out = array();
Expand All @@ -124,31 +113,37 @@ function make_html_map($map){
return $out;
}

function make_mapping($mapping, $dest){
function is_codepoint_field($field_name){
return in_array($field_name, array('unified', 'variations', 'docomo', 'au', 'softbank', 'google'));
}

function make_mapping($mapping, $src, $dest){

$result = array();

foreach ($mapping as $map){
if (empty($map[$src]))
continue;

$src_char = unicode_bytes($map['unified']);
$src_chars = is_array($map[$src]) ? $map[$src] : array($map[$src]);

if (!empty($map[$dest])){
foreach ($src_chars as $src_char){

$dest_char = unicode_bytes($map[$dest]);
}else{
$dest_char = '';
}
if (is_codepoint_field($src))
$src_char = unicode_bytes($src_char);

$result[$src_char] = $dest_char;
}
if (!empty($map[$dest])){

return $result;
}
$dest_char = is_codepoint_field($dest) ? unicode_bytes($map[$dest]) : $map[$dest];
}else{
$dest_char = '';
}

$result[$src_char] = $dest_char;

}
}

function make_mapping_flip($mapping, $src){
$result = make_mapping($mapping, $src);
$result = array_flip($result);
unset($result[""]);
return $result;
}

Expand Down
2 changes: 2 additions & 0 deletions build/inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function emoji_docomo_to_unified( $text){ return emoji_convert($text, 'docomo_to
function emoji_kddi_to_unified( $text){ return emoji_convert($text, 'kddi_to_unified'); }
function emoji_softbank_to_unified( $text){ return emoji_convert($text, 'softbank_to_unified'); }
function emoji_google_to_unified( $text){ return emoji_convert($text, 'google_to_unified'); }
function emoji_shortname_to_unified( $text){ return emoji_convert($text, 'shortname_to_unified'); }


#
Expand All @@ -20,6 +21,7 @@ function emoji_unified_to_docomo( $text){ return emoji_convert($text, 'unified_t
function emoji_unified_to_kddi( $text){ return emoji_convert($text, 'unified_to_kddi'); }
function emoji_unified_to_softbank( $text){ return emoji_convert($text, 'unified_to_softbank'); }
function emoji_unified_to_google( $text){ return emoji_convert($text, 'unified_to_google'); }
function emoji_unified_to_shortname( $text){ return emoji_convert($text, 'unified_to_shortname'); }
function emoji_unified_to_html( $text){ return emoji_convert($text, 'unified_to_html'); }
function emoji_html_to_unified( $text){ return emoji_convert($text, 'html_to_unified'); }

Expand Down
Loading