[haiku-commits] r38824 - haiku/trunk/src/apps/mediaplayer/interface

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 26 Sep 2010 22:32:39 +0200 (CEST)

Author: stippi
Date: 2010-09-26 22:32:38 +0200 (Sun, 26 Sep 2010)
New Revision: 38824
Changeset: http://dev.haiku-os.org/changeset/38824

Modified:
   haiku/trunk/src/apps/mediaplayer/interface/SubtitleBitmap.cpp
Log:
 * Added more comments to the code.
 * Cleanup ParseStates in case the input didn't have
   all closing tags.


Modified: haiku/trunk/src/apps/mediaplayer/interface/SubtitleBitmap.cpp
===================================================================
--- haiku/trunk/src/apps/mediaplayer/interface/SubtitleBitmap.cpp       
2010-09-26 20:25:57 UTC (rev 38823)
+++ haiku/trunk/src/apps/mediaplayer/interface/SubtitleBitmap.cpp       
2010-09-26 20:32:38 UTC (rev 38824)
@@ -163,9 +163,11 @@
        tagPos = string.Length();
        tagLength = 0;
 
+       // Find the next tag closest from the current position
+       // This way of doing it allows broken input with overlapping tags even.
        BString tag;
        for (int32 i = 0; i < kTagCount; i++) {
-               int32 nextTag = string.FindFirst(kTags[i], current);
+               int32 nextTag = string.IFindFirst(kTags[i], current);
                if (nextTag >= current && nextTag < tagPos) {
                        tagPos = nextTag;
                        tag = kTags[i];
@@ -173,6 +175,7 @@
        }
 
        if (tag != "") {
+               // Tag found, ParseState will change.
                tagLength = tag.Length();
                if (tag == "<b>") {
                        state = new ParseState(state);
@@ -197,7 +200,7 @@
                        }
                } else if (tag == "</b>" || tag == "</i>" || tag == "</u>"
                        || tag == "</font>") {
-                       // Pop state
+                       // Closing tag, pop state
                        if (state->previous != NULL) {
                                ParseState* oldState = state;
                                state = state->previous;
@@ -245,6 +248,7 @@
                int32 tagLength;
                bool stateChanged = find_next_tag(string, nextPos, tagLength, 
state);
                if (nextPos > pos) {
+                       // Insert text between last and next tags
                        BString subString;
                        string.CopyInto(subString, pos, nextPos - pos);
                        textView->Insert(subString.String());
@@ -253,6 +257,13 @@
                if (stateChanged)
                        apply_state(textView, state, font, changeColor);
        }
+
+       // Cleanup states in case the input text had non-matching tags.
+       while (state->previous != NULL) {
+               ParseState* oldState = state->previous;
+               state = state->previous;
+               delete oldState;
+       }
 }
 
 


Other related posts:

  • » [haiku-commits] r38824 - haiku/trunk/src/apps/mediaplayer/interface - superstippi