-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
248 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace AcidF0x\KoreanHandler; | ||
|
||
class Character | ||
{ | ||
private ?string $choseong = null; | ||
private ?string $jungseong = null; | ||
private ?string $jongseong = null; | ||
/** @var array|string[] */ | ||
private array $split = []; | ||
|
||
public function __construct(?string $choseong, ?string $jungseong, ?string $jongseong) | ||
{ | ||
$this->choseong = $choseong; | ||
$this->jungseong = $jungseong; | ||
$this->jongseong = $jongseong; | ||
} | ||
|
||
public function getChoseong(): ?string | ||
{ | ||
return $this->choseong; | ||
} | ||
|
||
public function setChoseong(?string $choseong): Character | ||
{ | ||
$this->choseong = $choseong; | ||
return $this; | ||
} | ||
|
||
public function getJungseong(): ?string | ||
{ | ||
return $this->jungseong; | ||
} | ||
|
||
public function setJungseong(?string $jungseong): Character | ||
{ | ||
$this->jungseong = $jungseong; | ||
return $this; | ||
} | ||
|
||
public function getJongseong(): ?string | ||
{ | ||
return $this->jongseong; | ||
} | ||
|
||
public function setJongseong(?string $jongseong): Character | ||
{ | ||
$this->jongseong = $jongseong; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return array|string[] | ||
*/ | ||
public function getSplit(): array | ||
{ | ||
return $this->split; | ||
} | ||
|
||
public function setSplit(): Character | ||
{ | ||
$split = [ | ||
$this->choseong, | ||
$this->jungseong | ||
]; | ||
|
||
if ($this->jongseong) { | ||
$split[] = $this->jongseong; | ||
} | ||
|
||
$this->split = $split; | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace AcidF0x\KoreanHandler; | ||
|
||
final class Constants | ||
{ | ||
/** @var int 한글 음절 첫글자 = 가 */ | ||
public const UNICODE_HANGUL_SYLLABLE_START = 44032; | ||
/** @var int 한글 음절 마지막 글자 = 힣 */ | ||
public const UNICODE_HANGUL_SYLLABLE_END = 55203; | ||
/** @var string[] 초성리스트 */ | ||
public const CHOSEONG_LIST = ["ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"]; | ||
/** @var string[] 중성리스트 */ | ||
const JUNGSEONG_LIST = ["ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ","ㅘ","ㅙ","ㅚ","ㅛ","ㅜ","ㅝ","ㅞ","ㅟ","ㅠ","ㅡ","ㅢ","ㅣ"]; | ||
/** @var string[] 종성리스트 */ | ||
const JONGSEONG_LIST = ["ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace AcidF0x\KoreanHandler; | ||
|
||
use ArrayAccess; | ||
use Iterator; | ||
|
||
class SeparateResult implements ArrayAccess, Iterator | ||
{ | ||
private int $position; | ||
/** @var array|Character */ | ||
private array $characters = []; | ||
|
||
public function __construct(array $characters = []) | ||
{ | ||
$this->position = 0; | ||
$this->characters = $characters; | ||
} | ||
|
||
public function offsetSet($offset, $value) { | ||
if (is_null($offset)) { | ||
$this->characters[] = $value; | ||
} else { | ||
$this->characters[$offset] = $value; | ||
} | ||
} | ||
|
||
public function offsetExists($offset): bool | ||
{ | ||
return isset($this->characters[$offset]); | ||
} | ||
|
||
public function offsetUnset($offset) | ||
{ | ||
unset($this->characters[$offset]); | ||
} | ||
|
||
public function offsetGet($offset): ?Character | ||
{ | ||
return $this->characters[$offset] ?? null; | ||
} | ||
|
||
public function rewind() | ||
{ | ||
$this->position = 0; | ||
} | ||
|
||
public function current(): Character | ||
{ | ||
return $this->characters[$this->position]; | ||
} | ||
|
||
public function key(): int | ||
{ | ||
return $this->position; | ||
} | ||
|
||
public function next() | ||
{ | ||
++$this->position; | ||
} | ||
|
||
public function valid(): bool | ||
{ | ||
return isset($this->characters[$this->position]); | ||
} | ||
|
||
public function getChoseongList(): array | ||
{ | ||
return array_map(fn(Character $char) => $char->getChoseong(), $this->characters); | ||
} | ||
|
||
public function getJungseongList(): array | ||
{ | ||
return array_map(fn(Character $char) => $char->getJungseong(), $this->characters); | ||
} | ||
|
||
public function getJongseongList(): array | ||
{ | ||
return array_filter( | ||
array_map(fn(Character $char) => $char->getJongseong(), $this->characters), | ||
fn($i) => $i !== null | ||
); | ||
} | ||
|
||
public function getSplitList(): array | ||
{ | ||
$result = []; | ||
/** @var Character $character */ | ||
foreach ($this->characters as $character) { | ||
array_push($result, ...$character->getSplit()); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
Oops, something went wrong.