Login Register
Frontpage Code library Pastebin

HyphenateString()

Author: Jare
Added: 8.8.2012 0:15
Edited: 8.8.2012 11:28
Category: Merkkijonot

Description

Tavuttaa merkkijonon suomen kielen tavutussääntöjen mukaisesti. Tämä ei ole täysin aukoton: se ei osaa tavuttaa oikein joitakin lainasanoja, esimerkiksi "demokratia". Lisäksi se tulkitsee vokaaleiksi ja konsonanteiksi ainoastaan suomalaiset aakkoset. Kaikki muut merkit tulkitaan välimerkeiksi, jotka sivuutetaan tavutuksessa, mutta jotka säilyvät edelleen lopputuloksessa. Esimerkiksi Citroën-automerkin ë-kirjainta funktio ei huomioi tavutuksessa. Å, Ä ja Ö toimivat oikein. Mode-parametrilla päätetään, mitä funktio palauttaa: Jos mode sisältää vähintään yhden merkin, modea käytetään tavutuksen välimerkkinä. Se voi siis sisältää useita merkkejä. Jos mode on tyhjä merkkijono, funktio palauttaa listan merkki-positioneista, joiden kohdalle funktio ehdottaa tavuviivan sijoittamista. Esimerkiksi paluuarvo "3 6 8" tarkoittaa, että ennen merkkiä 3 tulee tavuviiva, samoin ennen merkkiä 6 ja ennen merkkiä 8. Moden oletusarvo on "-", joten normaali tavuttaminen hoituu ilman mode-parametrin asettamista. Jos bugeja ilmenee, korjailen niitä mikäli kykenen.

Code

Select all
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
stri$ = "Tavuttaa merkkijonon suomen kielen tavutussääntöjen mukaisesti. Tämä ei ole täysin aukoton. Esimerkiksi nämä menee pieleen: demokratia, Citroën."
MakeError HyphenateString(stri)

Function HyphenateString(stri$, mode$="-")
	//Hyphenates Finnish Text.
	//mode parameter controls the hyphenation:
	// - mode <> "": uses mode's value As a hyphen And returns the hyphenated Text. Length of mode can also be greater than 1.
	// - mode = "": returns a list of character positions where the Function suggests that a hyphen would be inserted. Example: "3,7,10".
	//Rules can be found from http://www.cs.hut.fi/Opinnot/T-106.1240/s2007/harjoitukset/kierros_2/harj_1/index.html (checked 2012-08-07),
	//but they are written in Finnish.
	original_stri$	= stri
	stri			= Lower(stri)
	vowels$			= "aeiouyåäö"
	result$			= ""
	hyphenated		= 1
	For i = 2 To Len(stri)
		chr1$	= Mid(stri, i-1,1)
		chr2$	= Mid(stri, i,1)
		If False=IsLetter(chr1) Or False=IsLetter(chr2) Then Goto continue
		
		//Rules
		hyphenate = False
		If InStr(vowels, chr1) And False = InStr(vowels, chr2) Then
			//A) Hyphenate If a consonant comes After a vowel.
			wovel_follows = False
			For n = i+1 To Len(stri)
				//Find Last consonant in a queue of consonants.
				chr_n$			= Mid(stri, n,1)
				wovel_follows	= InStr(vowels, chr_n)
				If wovel_follows Or False = IsLetter(chr_n) Then
					n-1
					Exit
				EndIf
			Next n
			If wovel_follows Then hyphenate = n - (n>=Len(stri)) //Only hyphenate If the queue of consonants is followed by a vowel.
		EndIf
		If InStr(vowels, chr1) And InStr(vowels, chr2) Then
			//B) Hyphenate If a vowel comes After a vowel, unless an exception happens.
			exception = False
			If chr1 = chr2 Then exception = True
			If chr2 = "i" Then exception = True
			If InStr("au,eu,ey,ie,iu,ou,uo,yö,äy,öy", chr1+chr2) Then exception = True
			If Not exception Then
				//No exceptions, so do hyphenating
				hyphenate = i
			Else
				//C) Exception For exceptions: If a vowel comes After the chr1+chr2 pair, hyphenate between chr2 And the vowel.
				If i = Len(stri) Then Exit
				chr3$ = Mid(stri, i+1,1)
				If InStr(vowels, chr3) Then hyphenate = i+1
			EndIf
		EndIf
		
		If hyphenate > hyphenated Then
			If mode = "" Then
				If result <> "" Then result + " "
				result + hyphenate
			Else
				result = result + Mid(original_stri, hyphenated, hyphenate-hyphenated) + mode
			EndIf
			hyphenated = hyphenate
		EndIf
		continue:
	Next i
	If mode <> "" Then result = result + Mid(original_stri, hyphenated)
	Return result
EndFunction

Function IsLetter(char$)
	//Checks If a given character is a-z, å, ä Or ö.
	//NOTE! Uppercase letters are considered As non-letters! 
	ascii = Asc(char)
	Return (ascii >= 97 And ascii <= 122) Or ascii = 228 Or ascii = 229 Or ascii = 246
EndFunction

Comments

#36 Sent by: MaGetzUb, 26.8.2012 19:07

Mielenkiintoista. Miksi olet kommentoinut koodin englanniksi, vaikka koodi/funktio itse tavuttaa suomenkielellä lauseita?

#39 Sent by: Jare, 19.9.2012 19:42

Koska koodaan täysin englanniksi joka paikassa. En vaihda koodaustyyliäni vaikka ohjema olisikin muuta kieltä kuin englantia varten. :)

#40 Sent by: Pettis, 8.12.2012 11:56

Englanti sopii muutenkin ohjelmoinnissa kommentteihin paremmin, koska yleensä kaikki ohjelmointikielien avainsanat ovat englannin kielestä. Englanti on koodareiden ammattikieli :)

#1502 Sent by: Raymondkiz, 19.4.2021 19:36

north korea




channel news asiaterrorist attack

#1503 Sent by: Raymondkiz, 20.4.2021 18:03

singapore news




terrorist attackwonho

#1504 Sent by: XyampiZdeckiz, 21.4.2021 7:06

trump china <a href=https://www.tekcrispy.com/2019/11/09/datanumen-reparar-zip/>wonhoterrorist attack</a>

#1505 Sent by: Rodneygob, 22.4.2021 20:53

<a href=https://kpopfashionstore.com/>kpop merch</a>
<a href=https://kpopfashionstore.com/>kpop stores near me</a>

When it comes to amassing apparel and equipment for the idols, Korean pop new music is a real option. Korean pop audio has been so common for thus extended that there are now numerous shops that concentrate on marketing this type of items. No matter if you need to go buying BTS merch, or perhaps you need to acquire a terrific present for that idol you admire the most, there are actually many different retailers which will supply you with the products you will need at extremely competitive prices.

In case you take place to Reside near me, you'll likely locate Kpop Merch in my hometown, South Korea. This is certainly among the best outlets I have at any time visited. Each element of Korean pop tunes and trend is represented On this 1 store. You should purchase everything from clothing and components to clothes and components related to BTS search. With The range of items on provide, that you are bound to uncover something that you love.

A further area which you could come across lots of Korean new music associated goods is usually a web site called Shopbop. The main reason that it's considered as the most effective Korean keep is due to the fact that they are in small business for almost 5 years now. The number of items that you will discover Here's awesome and it just looks as if more merchants are coming up in just about every town. Their stock is sort of two times as major as one other stores that I've noticed and it seems like These are intending to grow even additional. The sole downside would be that the price ranges at this site are marginally greater than the opposite merchants due to the fact their stock is so much bigger.

A different place which i highly recommend for getting Korean pop merch is eBay. If you need to have the capacity to get some genuinely distinctive products for a very affordable price tag, then this is an excellent place to glance. Not like one other two sites, eBay allows you to use the PayPal payment technique so you will not have to worry about dealing with tricky men and women and you can even buy presents for the idols on the net. There are plenty of Korean keep in the vicinity of me that also market things on the net but none of them promote pretty much as good of Korean pop tunes as eBay does.

One more wonderful place for getting Korean merch is on the web, but not within an precise store is the favored Korean store named Jeju. . Their goods are very similar to eBay but with the next rate because the store gives lots of exceptional objects that aren't available any place else.

And finally, if you are searching for an excellent gift for that Tremendous idol in your life, you might want to look into the Korean retail store named MySpace. If you want to really know what other Korean famous people are nearly, This great site is surely an complete should pay a visit to for you personally. There are tons of terrific objects readily available listed here but the costs are not much too poor and you will also be capable to see shots of those famous people so you will really know what the item is like in actual lifetime.
<a href=https://kpopfashionstore.com/collections/nct-merch>nct merch</a>
<a href=https://kpopfashionstore.com/collections/seventeen-merch>seventeen merch</a>

#1506 Sent by: KenCreedmoorinfaf, 25.4.2021 14:32


jokowi
<a href=http://ask-leo.com/how_do_i_upgrade_my_outlook_pst_to_2003_format.html>
news on north koreaV</a>

#1507 Sent by: RalphDiumn, 27.4.2021 1:16

Vietnam city capital of China <a href=https://www.datanumen.com/pdf-repair/> capital 5 </a>

#1508 Sent by: Donaldsit, 28.4.2021 10:15

Bravo, what necessary phrase..., an excellent idea
<a href=https://smokinjacksbarbque.com>smokinjacksbarbque.com</a>

#1509 Sent by: Rodneygob, 6.5.2021 12:41

<a href=https://kpopfashionstore.com/>kpop stores</a>
<a href=https://kpopfashionstore.com/>kpop store in usa</a>

When it comes to accumulating clothes and add-ons on your idols, Korean pop songs is a true decision. Korean pop tunes has long been so well-liked for therefore extensive there are now hundreds of stores that specialize in selling this kind of merchandise. Regardless of whether you want to go purchasing for BTS merch, and even you want to obtain an awesome present for that idol you admire essentially the most, there are actually many different retailers that may offer you the products you'll need at really competitive selling prices.

For those who materialize to live near to me, you'll likely come across Kpop Merch in my hometown, South Korea. This can be among the best merchants I've ever frequented. Each individual element of Korean pop tunes and trend is represented On this just one store. You can purchase anything from apparel and components to apparel and components related to BTS look for. With The range of items on present, you will be certain to uncover something that you're keen on.

Yet another put which you can uncover loads of Korean tunes related solutions is usually a web site identified as Shopbop. The reason that it is considered as the top Korean shop is due to The truth that they have been in enterprise for nearly 5 years now. The number of products that you can find here is awesome and it just looks as if much more outlets are developing in each individual metropolis. Their stock is almost 2 times as huge as one other suppliers that I've seen and it seems like They may be planning to broaden even even further. The one downside would be that the rates at This web site are a little bit larger than another shops due to the fact their inventory is so much larger.

A further location which i highly endorse for getting Korean pop merch is eBay. If you need to be capable of get some definitely one of a kind merchandise for a very realistic cost, then this is an excellent spot to appear. In contrast to the other two internet sites, eBay helps you to use the PayPal payment procedure so you will not have to worry about dealing with difficult individuals and you can even invest in presents to your idols on the web. There are plenty of Korean shop around me that also provide things online but none of these sell as good of Korean pop music as eBay does.

A further good position for getting Korean merch is on-line, but not in an actual store is the popular Korean keep named Jeju. . Their items are very similar to eBay but with a better selling price because the store features loads of exceptional objects that are not obtainable any place else.

Lastly, if you are looking for a good reward for that Tremendous idol in your lifetime, you may want to look into the Korean keep named MySpace. If you want to know what other Korean celebrities are approximately, This page is surely an complete need to go to for yourself. There are a lot of good products readily available listed here but the costs aren't also bad and you will also have the capacity to see pictures of these superstars so you might really know what the solution is like in actual existence.
<a href=https://kpopfashionstore.com/collections/exo-merch>exo hoodie</a>
<a href=https://kpopfashionstore.com/collections/kpop-fashion>korean clothing online</a>

#1510 Sent by: SdvillLayem, 17.5.2021 23:49

<a href=https://chimmed.ru/>chem-impex international, inc.</a>
Tegs: chem-lab be https://chimmed.ru/

<u>polylc</u>
<i>polylc com</i>
<b>polylc inc.</b>

#1511 Sent by: XyampiZdeckiz, 18.6.2021 23:39

terrorist attack <a href=https://www.altech-ads.com/product/10004672/Advanced-Zip-Repair.html>seungrikim jong un</a>

Leave a comment

You must be logged in to comment.