Skip to content

Commit

Permalink
LineContents:replaceTags(): make insertion of remaining tags not prev…
Browse files Browse the repository at this point in the history
…iously found in the line optional; automatically create tag section at the beginning of the line if insertion of remaining tags was requested at index 1
  • Loading branch information
line0 committed May 12, 2015
1 parent 67bb4ec commit 0003623
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions l0/ASSFoundation/LineContents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ return function(ASS, ASSFInst, yutilsMissingMsg, createASSClass, re, util, unico
return tags
end

function LineContents:replaceTags(tagList, start, end_, relative) -- TODO: transform and reset support
function LineContents:replaceTags(tagList, start, end_, relative, insertRemaining) -- TODO: transform and reset support
insertRemaining = default(insertRemaining, true)
if type(tagList)=="table" then
if tagList.class == ASS.Section.Tag then
tagList = ASS.TagList(tagList)
Expand Down Expand Up @@ -243,7 +244,15 @@ return function(ASS, ASSFInst, yutilsMissingMsg, createASSClass, re, util, unico
end

-- insert remaining tags (not replaced) into the first processed section
self:insertTags(toInsert, start or 1, nil, not relative)
-- to easily allow for the function to be used to insert tags (overwriting existing ones)
-- create tag section at index 1 when it was requested as the start of the replacement
-- but doesn't yet exist
if insertRemaining then
start = start or 1
if start == 1 and not relative and not ASS:instanceOf(self.sections[1], ASS.Section.Tag) then
self:insertSections(ASS.Section.Tag(toInsert), 1)
else self:insertTags(toInsert, start, nil, not relative) end
end
end

function LineContents:removeTags(tags, start, end_, relative)
Expand Down

0 comments on commit 0003623

Please sign in to comment.