Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Quellcode |
|
1 2 3 4 |
www.blubb.ch -> <a href="www.blubb.ch">www.blubb.ch</a> <a href="www.blubb.ch">www.blubb.ch</a> -> <a href="www.blubb.ch">www.blubb.ch</a> <a href="www.blubb.ch">aaa</a> -> <a href="www.blubb.ch">aaa</a> <a href="...">asdf</a>www.blubb.ch -> <a href="...">asdf</a> <a href="www.blubb.ch">www.blubb.ch</a> |
Quellcode |
|
1 |
(http://)?www\\.\\S+\\.\\S+ |
Quellcode |
|
1 |
<a.*?href=\"(.*?)\">(.*?)</a> |
Quellcode |
|
1 |
(?:<a\s+href\s*\=\s*")?((?:http:\/\/)?www\..+?\.[a-z]+)(?:">)?\s*((?:http:\/\/)?www\..+?\.[a-z]+|[\w\-_]+)?(?:\s*<\/a>)? |
C-/C++-Quelltext |
|
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 |
public static String tidyLinks(String text) { StringBuffer ret = new StringBuffer(); StringBuffer link = new StringBuffer(); boolean linkActive = false; char last = ' '; char preLast = ' '; char prepreLast = ' '; boolean aTagOpen = false; for(int i = 0; i < text.length(); ++i) { char current = text.charAt(i); if(current == 'a' && last == '<') // detect opening a tags "<a" aTagOpen = true; if(current == '>' && last == 'a' && preLast == '/' && prepreLast == '<') // detect closing a tags "</a>" aTagOpen = false; if(!aTagOpen) // do the replacement just if no a tag is opened { if(current == '.' && last == 'w' && preLast == 'w' && prepreLast == 'w') { link.append("www"); linkActive = true; // remove already appended w's ret.deleteCharAt(ret.length()-1); ret.deleteCharAt(ret.length()-1); ret.deleteCharAt(ret.length()-1); } if(linkActive) { if(current == ' ' || i == text.length()-1) // end of link { linkActive = false; if(i == text.length()-1 && current != ' ') link.append(current); // append corrected version of link to return value String plainLink = link.substring(0); ret.append("<a href=\""+plainLink+"\">"+plainLink+"</a>"); if(current == ' ') ret.append(current); link = new StringBuffer(); } else // gather link { link.append(current); } } else // no link so just add it to the return value { ret.append(current); } } else // an a tag is open so just append it { ret.append(current); } prepreLast = preLast; preLast = last; last = current; } return ret.substring(0); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
testCase("www.blubb.ch ","<a href=\"www.blubb.ch\">www.blubb.ch</a> "); testCase("<a href=\"\"></a>www.blubb.ch","<a href=\"\"></a><a href=\"www.blubb.ch\">www.blubb.ch</a>"); testCase("<a href=\"\"></a><a href=\"www.blubb.ch\">www.blubb.ch</a>","<a href=\"\"></a><a href=\"www.blubb.ch\">www.blubb.ch</a>"); testCase("<a href=\"\"></a><a href=\"www.blubb.ch\">aaa</a>","<a href=\"\"></a><a href=\"www.blubb.ch\">aaa</a>"); testCase("ww.asfd.ch","ww.asfd.ch"); testCase("www.a.ch www.b.ch","<a href=\"www.a.ch\">www.a.ch</a> <a href=\"www.b.ch\">www.b.ch</a>"); testCase("ww www.b.ch","ww <a href=\"www.b.ch\">www.b.ch</a>"); testCase("", ""); testCase("www.blubb.ch ","<a href=\"www.blubb.ch\">www.blubb.ch</a> "); testCase("www.blwwwubb.ch","<a href=\"www.blwwwubb.ch\">www.blwwwubb.ch</a>"); testCase("www.asdf.ert.ch", "<a href=\"www.asdf.ert.ch\">www.asdf.ert.ch</a>"); |
Werbeanzeige