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

๐Ÿ”€ :: (#1258) ๋‹‰๋„ค์ž„ ์ž…๋ ฅ ์กฐ๊ฑด ์ถ”๊ฐ€ #1274

Merged
merged 4 commits into from
Sep 1, 2024
Merged
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
8 changes: 6 additions & 2 deletions Projects/Features/BaseFeature/Resources/Base.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,17 @@
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="cfO-nl-nfD">
<rect key="frame" x="20" y="145" width="316" height="18.666666666666657"/>
<rect key="frame" x="20" y="145" width="303" height="18.666666666666657"/>
<color key="textColor" name="gray800"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" returnKeyType="done" smartDashesType="no" smartInsertDeleteType="no" smartQuotesType="no"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="O6b-uG-uWT">
<rect key="frame" x="341" y="137.33333333333334" width="32" height="34"/>
<rect key="frame" x="328" y="142.33333333333334" width="45" height="24"/>
<constraints>
<constraint firstAttribute="height" constant="24" id="XQd-rR-LNT"/>
<constraint firstAttribute="width" constant="45" id="laI-2j-1tT"/>
</constraints>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" title="์ทจ์†Œ">
<color key="titleColor" name="gray400"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ private extension MultiPurposePopupViewController {
cancelButton.layer.borderWidth = 1
cancelButton.backgroundColor = .white
cancelButton.isHidden = true
cancelButton.contentEdgeInsets = .init(top: 3, left: 12, bottom: 3, right: 12)

confirmLabel.font = DesignSystemFontFamily.Pretendard.light.font(size: 12)
confirmLabel.isHidden = true
Expand Down Expand Up @@ -184,21 +183,43 @@ extension MultiPurposePopupViewController: UITextFieldDelegate {
replacementString string: String
) -> Bool {
guard let char = string.cString(using: String.Encoding.utf8) else { return false }
let isBackSpace = strcmp(char, "\\b")
let isBackSpace: Bool = strcmp(char, "\\b") == -92

let latinCharCount = textField.text?.alphabetCharacterCeilCount ?? 0
let currentText = textField.text ?? ""
let latinCharCount: Double = currentText.alphabetCharacterCount

if let lastChar = currentText.last,
latinCharCount <= Double(viewModel.type.textLimitCount) {
// ์™„์„ฑ๋˜์ง€ ์•Š์€ ํ•œ๊ธ€์ธ ๊ฒฝ์šฐ
if lastChar.isIncompleteHangul {
return true
}

// ์™„์„ฑ๋œ ํ•œ๊ธ€์ด์ง€๋งŒ, ์ถ”๊ฐ€๋กœ ์ž์Œ์ด ๊ฒฐํ•ฉ๋  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ
if !lastChar.isIncompleteHangul &&
lastChar.canAddAdditionalJongseong {
return true
}
}

guard isBackSpace || latinCharCount < Double(viewModel.type.textLimitCount) else { return false }

guard isBackSpace == -92 || latinCharCount < viewModel.type.textLimitCount else { return false }
return true
}
}

private extension String {
var alphabetCharacterCeilCount: Int {
var alphabetCharacterCount: Double {
let count = reduce(0) { count, char in
return count + (char.isAlphabetCharacter ? 0.5 : 1)
}
return count
}

var alphabetCharacterCeilCount: Int {
let count = reduce(0) { count, char in
return count + (char.isAlphabetCharacter ? 0.5 : 1)
}
return Int(ceil(count))
}
}
Expand All @@ -207,4 +228,60 @@ private extension Character {
var isAlphabetCharacter: Bool {
return self.unicodeScalars.allSatisfy { $0.isASCII && $0.properties.isAlphabetic }
}

/// ์™„์„ฑ๋˜์ง€ ์•Š์€ ํ•œ๊ธ€ ์—ฌ๋ถ€
var isIncompleteHangul: Bool {
guard let scalar = unicodeScalars.first else { return false }

// ํ•œ๊ธ€ ๋ฒ”์œ„์— ์žˆ๋Š”์ง€ ํ™•์ธ (์œ ๋‹ˆ์ฝ”๋“œ ๊ฐ’ ๋ฒ”์œ„ ์ฒดํฌ)
let hangulBase: UInt32 = 0xAC00
let hangulEnd: UInt32 = 0xD7A3

if scalar.value >= hangulBase && scalar.value <= hangulEnd {
let syllableIndex = (scalar.value - hangulBase)
let isCompleted = syllableIndex % 28 != 0
return !isCompleted
}

// ์™„์„ฑ๋˜์ง€ ์•Š์€ ์ž๋ชจ๋‚˜ ์กฐํ•ฉ ์ค‘์ธ ๊ฒฝ์šฐ
return (scalar.value >= 0x1100 && scalar.value <= 0x11FF) || // ์ดˆ์„ฑ ์ž๋ชจ (ํ˜„๋Œ€ ํ•œ๊ธ€์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์ดˆ์„ฑ, ์ค‘์„ฑ, ์ข…์„ฑ ๋“ฑ์˜ ์กฐํ•ฉ์šฉ ์ž๋ชจ)
(scalar.value >= 0x3130 && scalar.value <= 0x318F) || // ํ˜ธํ™˜์šฉ ์ž๋ชจ (๊ตฌ์„ฑ๋œ ํ•œ๊ธ€ ์ž๋ชจ, ์˜› ํ•œ๊ธ€ ์ž๋ชจ ๋“ฑ)
(scalar.value >= 0xA960 && scalar.value <= 0xA97F) || // ํ™•์žฅ A (์˜› ํ•œ๊ธ€ ์ž๋ชจ์˜ ์ผ๋ถ€)
(scalar.value >= 0xD7B0 && scalar.value <= 0xD7FF) // ํ™•์žฅ B (์˜› ํ•œ๊ธ€ ์ž๋ชจ์˜ ์ผ๋ถ€)
}

/// ํ•œ๊ธ€ ์Œ์ ˆ์ด ์ข…์„ฑ์„ ๊ฐ€์กŒ์œผ๋‚˜ ์ถ”๊ฐ€์ ์ธ ์ข…์„ฑ์ด ๋” ๊ฒฐํ•ฉ๋  ์ˆ˜ ์žˆ๋Š”์ง€ ์—ฌ๋ถ€ ํ™•์ธ
var canAddAdditionalJongseong: Bool {
guard let scalar = unicodeScalars.first else { return false }

// ํ•œ๊ธ€ ์Œ์ ˆ ์œ ๋‹ˆ์ฝ”๋“œ ๋ฒ”์œ„: U+AC00 ~ U+D7A3
let hangulBase: UInt32 = 0xAC00
let hangulEnd: UInt32 = 0xD7A3

guard scalar.value >= hangulBase && scalar.value <= hangulEnd else {
return false
}

// ์ข…์„ฑ์— ํ•ด๋‹นํ•˜๋Š” ์ธ๋ฑ์Šค๋ฅผ ๊ณ„์‚ฐ
let syllableIndex = scalar.value - hangulBase
let jongseongIndex = Int(syllableIndex % 28)

// ์ข…์„ฑ์ด ์žˆ์„ ๋•Œ ์ถ”๊ฐ€ ์ข…์„ฑ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ๋ฅผ ํŒ๋ณ„
let canHaveDoubleJongseong: Bool

switch jongseongIndex {
case 1: // ใ„ฑ (U+11A8)
canHaveDoubleJongseong = true
case 4: // ใ„ด (U+11AB)
canHaveDoubleJongseong = true
case 8: // ใ„น (U+11AF)
canHaveDoubleJongseong = true
case 17: // ใ…‚ (U+11B7)
canHaveDoubleJongseong = true
default:
canHaveDoubleJongseong = false
}

return canHaveDoubleJongseong
}
}
Loading