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 :)

#1517 Sent by: Wilburnkeepe, 15.9.2021 3:18

<a href=https://ca.alt.com>alt.com</a>

#1518 Sent by: Stevenchedo, 16.9.2021 0:48

9229450e8b
Stevenchedo chedo
uphok
new
nesCoefeapboarbus
Sockeviermiseemalket
steaDotizheattyFleek

#1519 Sent by: FloydNeady, 16.9.2021 23:12

Source:
https://forum2.shareman.tv/viewtopic.php?f=21&t=76492

#1520 Sent by: FloydNeady, 17.9.2021 0:43

Source:
http://forum.unm.org.ua/viewtopic.php?f=12&t=32538

#1521 Sent by: Wilburnkeepe, 17.9.2021 0:44

[url=https://ca.alt.com]alt.com[/url]

#1522 Sent by: FloydNeady, 17.9.2021 14:02

Source:
http://ya.ukrbb.net/viewtopic.php?f=17&t=377094

#1523 Sent by: Stevenchedo, 18.9.2021 0:17

9229450e8b
Stevenchedo chedo
uphok
new
nesCoefeapboarbus
Sockeviermiseemalket
steaDotizheattyFleek

#1524 Sent by: Stevenchedo, 19.9.2021 20:04

9229450e8b
Stevenchedo chedo
uphok
new
nesCoefeapboarbus
Sockeviermiseemalket
steaDotizheattyFleek

#1525 Sent by: Thomasedins, 21.9.2021 15:14

If you have a possibility to look into the Web casino site, you will undoubtedly discover web sites that supply "120 Free Rotates Genuine Money." This sounds as well great to be real. Nevertheless, how can these internet sites provide such giveaways? The purpose of this article is to go over how online casinos hand out free rotates and exactly how you can get your hands on them.

The first concern that the majority of people ask when they learn about "120 free rotates for real cash" is if these offers really exist. The casino sites certainly do not make this type of deal simply to attract brand-new players to register. Instead, they are providing these bonuses so that existing players would remain loyal to their casinos. You may assume that existing gamers would certainly not mind obtaining something free of charge if it means that they will certainly maintain coming back to the online casino. The gambling establishments recognize this very well and that is why they supply "free" rotates with deposits.

Joining these casino sites would certainly mean that you accept play the video games for a set number of spins with a provided period. In return, the gambling establishment's honor you with factors that can be utilized as chips or benefit points. Prior to signing up with an on-line casino site totally free rotates genuine cash, make sure that you read the small print of the agreement. Discover what are the severe terms of the deal. There are substantial terms that ought to be included in the agreement.

The major problem that you should be concerned about when you find out about "down payment complimentary rotates for real cash" deals is the reality that a lot of them require you to pay a down payment. A lot of these deals need you to make a single deposit before you can take pleasure in the perk. Some supply certain incentives in lieu of your first down payment. Others allow you to make multiple deposits to obtain far better chances of winning. Hence, it is very important that you get all the details in writing to stay clear of future complications.

As soon as you have actually subscribed to play these video games, make sure to check out the guidelines meticulously. A lot of these on the internet casinos would certainly not enable you to play greater than one game per hour. Likewise, make sure to review the reward details. Find out how much you would be obtaining for every spin. It is essential to keep in mind that many online casinos do not bother with the first 10 spins; hence, it is a good idea to select the games that you can win actual cash on.

Most of these offers do not discuss any limitations on the number of free rotates. This makes it feasible for you to keep winning games after transferring UK extra pounds. There are two methods to win with these gambling enterprises. Either you win a dealt with prize on the initial spin, or you get a comparable amount in a kind of bonus offer spins. If you pick the benefit choice, take care not to register for way too many gambling enterprises.

[url=https://websitem.info] Related post referring to The More You Play the More Zito Points You Earn Which Get You Reward Cards [/url] with how to win real money online gambling now.

You can also get free cash in various other means. Some of these online video games use you totally free credit reports to wager. If you bank on the exact same video game as lots of people, you would certainly wind up spending much more in betting charges. Hence, it is much better that you pick the games that let you win real cash without having to use your bank card. The majority of the casino site firms supply register perks. These give you totally free credit reports to play different on-line video games.

If you really intend to appreciate playing the ports, it is far better to invest a couple of mins of your time to discover the most effective offers offered. Consider the slot web sites and also review the perk details before you choose to register. The totally free rotates supplied by the majority of the on-line gambling establishments are a superb way to win genuine cash.

Also you can visit BusinessWire media outlet portal to check the [url=http://siptrunkvoipbusinessphone.shop/]SIP Trunk VoIP Business Phone Solutions News, Reviews, Tips and Information[/url] and many more interesting posts and breaking industry news, in North America and around the globe.

Article original source: [url=http://postizo.mex.tl/?gb=1#top]Exactly How To Break Out Spins Genuine Money From Online Gambling Establishments[/url] 428f227

#1526 Sent by: Thomasedins, 22.9.2021 9:13

If you have a possibility to have a look at the Web casino, you will certainly locate websites that offer "120 Free Spins For Real Money." This sounds as well great to be real. Besides, how can these sites deliver such freebies? The objective of this article is to discuss how casinos give away cost-free spins and also just how you can get your hands on them.

The first concern that lots of people ask when they find out about "120 cost-free rotates genuine money" is if these offers truly exist. The gambling enterprises definitely do not make this kind of deal just to lure new gamers to register. Rather, they are offering these rewards so that existing players would stay devoted to their online casinos. You may believe that existing players would certainly incline obtaining something for free if it implies that they will maintain returning to the online casino. The online casinos know this very well and that is why they offer "cost-free" spins with deposits.

Signing up with these gambling establishments would certainly indicate that you agree to play the games for a set number of spins with a provided time frame. In return, the casino site's award you with points that can be utilized as chips or incentive points. Before registering with an online gambling enterprise complimentary rotates for real money, make certain that you check out the fine print of the contract. Learn what are the significant regards to the offer. There are significant terms that need to be included in the contract.

The significant problem that you must be worried about when you find out about "down payment free rotates genuine cash" bargains is the reality that most of them require you to pay a down payment. A lot of these deals need you to make a single deposit prior to you can take pleasure in the incentive. Some offer certain bonus offers instead of your preliminary deposit. Others permit you to make multiple deposits to acquire far better opportunities of winning. Hence, it is very important that you get all the information in writing to stay clear of future complications.

Once you have actually registered to play these video games, make certain to review the rules very carefully. Most of these on-line gambling establishments would certainly not allow you to play greater than one game per hour. Additionally, make certain to read the benefit details. Figure out just how much you would certainly be obtaining for each spin. It is necessary to note that most gambling enterprises do not bother with the initial 10 rotates; therefore, it is a good idea to pick the video games that you can win genuine cash on.

Most of these deals do not point out any restrictions on the variety of free rotates. This makes it feasible for you to keep winning games after depositing UK extra pounds. There are two means to win with these online casinos. Either you win a repaired reward on the initial spin, or you receive an equal quantity in a form of bonus rotates. If you select the incentive alternative, beware not to register for a lot of gambling establishments.

[url=https://websitem.info] News of the day with reference to 45 Year Old Patricia Challenged With $10 Free Slot Play [/url] with gambling online win real money now.

You can likewise secure free cash in various other means. Several of these on-line games provide you free credit reports to bet. If you bet on the exact same video game as lots of people, you would wind up investing extra in betting costs. Hence, it is much better that you choose the games that let you win actual money without needing to utilize your charge card. A lot of the casino companies use register perks. These provide you complimentary debts to play various online games.

If you actually want to enjoy playing the slots, it is much better to spend a couple of minutes of your time to figure out the most effective deals available. Check out the port sites as well as check out the benefit information prior to you make a decision to subscribe. The totally free spins provided by most of the online gambling establishments are an outstanding method to win real money.

Also you can visit BusinessWire media outlet portal to check the [url=http://laveuseapression.shop/]Laveuses a Pression Web Shop et Blogue[/url] and many more interesting posts and breaking industry news, in North America and around the globe.

Article original source: [url=http://medicinabiologicapuebla.com.mx/?gb=1#top]Just How To Secure Free Spins Genuine Cash From Online Online Casinos[/url] cf2f6b5

Leave a comment

You must be logged in to comment.