[−][src]Crate josa
Josa helps you append josa to a string in idiomatic way.
It has three approaches:
push_josa
method onString
+
,+=
operator overloading- A pure function
select
that selects appropriate josa
Example: push_josa
method
push_josa
method works the same way as push_str
.
It appends a given Josa
onto the end of this String
.
Note that it does mutate the string,
so you need to declare the String
as mutable.
use josa::JosaExt; use josa::{EulReul, EunNeun}; let mut user = "나".to_owned(); let mut you = "님".to_owned(); user.push_josa(EulReul); you.push_josa(EunNeun); assert_eq!( format!("{} 버리고 가시는 {}", user, you), "나를 버리고 가시는 님은" );
Example: +
, +=
operator overloading
+
, +=
concatenates String
with appropriate Josa
.
+
consumes the String
on the left-hand.
This is done to avoid allocating a new String
and copying the entire contents.
use josa::{EunNeun, IGa}; let user = "유진".to_owned(); let mackerel = "고등어".to_owned(); assert_eq!( format!("{} {} 먹고싶다", user + EunNeun, mackerel + IGa), "유진은 고등어가 먹고싶다" );
Example: A pure function that selects appropriate josa
Sometimes we need to append a josa to formatted text like
<span class="bold">곡괭이</span>
.
In that case, last character can be part of tag, which is not a Hangul Syllable.
select
is used to get only josa, instead of appending it.
use josa::select; use josa::Eu; let pick = "곡괭이"; assert_eq!( format!( r#"<span class="bold">{}</span>{}로 채취하세요."#, pick, select(pick, Eu)? ), r#"<span class="bold">곡괭이</span>로 채취하세요."# ); let hand = "손"; assert_eq!( format!( r#"<span class="bold">{}</span>{}로 채취하세요."#, hand, select(hand, Eu)? ), r#"<span class="bold">손</span>으로 채취하세요."# );
Edge cases
For push_josa
, +
, and +=
, since they are infallible,
they handle edge cases in their own way.
Empty String
If given String
is empty, it does not push any josa.
use josa::{JosaExt, IGa}; let mut empty = "".to_owned(); empty.push_josa(IGa); assert_eq!(empty, "");
Non Hangul Syllable character
If given String
ends with character other than Hangul Syllable,
it pushes 이(가)
formatted josa.
use josa::{JosaExt, IGa, Eu}; let mut curry = "curry".to_owned(); curry.push_josa(IGa); assert_eq!(curry, "curry이(가)"); let mut pioneer = "pioneer".to_owned(); pioneer.push_josa(Eu); assert_eq!(pioneer, "pioneer(으)"); // you can append 로서
Supported josas
Currently we supports:
- 은/는
- 이/가
- 을/를
- 과/와
- 이/(empty) (이다/다, 이나/나, 이란/란, 이든가/든가, 이나마/나마, 이야말로/야말로, 이랑/랑, 이여/여, 이며/며)
- 으/(empty) (으로/로, 으로서/로서, 으로써/로써, 으로부터/로부터)
Re-exports
pub use Josa::*; |
Enums
Error | Error type for appending josa to a string. Occurs when the string is empty, or does not end with Hangul Syllable. |
Josa | Enum of josas that are selected depending on the string in front of it. |
Traits
JosaExt |
Functions
select | Select appropriate josa for a string. |
Type Definitions
Result | A specialized |