「モジュール:SignalinstWiki」の版間の差分

編集の要約なし
編集の要約なし
 
(同じ利用者による、間の2版が非表示)
27行目: 27行目:
if propertySplit == nil or propertySplit == '' then propertySplit = "、" end
if propertySplit == nil or propertySplit == '' then propertySplit = "、" end
-- Valueを分割
    -- 元の propertyValue に「など」が含まれているかチェック
-- 分割された各要素を一時的に保存するテーブル
    local hasNado = false
    if string.find(propertyValue, "など") then
        hasNado = true
    end
 
    -- Valueを分割
local splitValues = {}
local splitValues = {}
 
local pattern = "(.-)" .. propertySplit
local pattern = "(.-)" .. propertySplit -- gmatchのパターン。'%' はエスケープ不要でリテラルの '%' を指す。
-- propertyValue の末尾に propertySplit を追加することで、最後の要素が正しく取得されるようにする
-- propertyValue の末尾に propertySplit を追加することで、最後の要素が正しく取得されるようにする
38行目: 42行目:
         -- 各要素の前後の空白をトリム(取り除く)
         -- 各要素の前後の空白をトリム(取り除く)
         local trimmedPart = part:match("^%s*(.-)%s*$")
         local trimmedPart = part:match("^%s*(.-)%s*$")
       
        -- ここで「など」を空文字列に置き換える処理
        -- 各部分から「など」を削除してからリストに追加する
        trimmedPart = string.gsub(trimmedPart, "など", "")
       
         if trimmedPart ~= '' then -- 空文字列でない場合のみ追加
         if trimmedPart ~= '' then -- 空文字列でない場合のみ追加
             table.insert(splitValues, string.gsub(trimmedPart, "など", "")) -- 「など」は置き換え
             table.insert(splitValues, trimmedPart)
         end
         end
     end
     end
49行目: 58行目:
     end
     end
      
      
     -- 各プロパティを改行で連結して返す
     -- ここで最終的な文字列を構築
     return table.concat(smwProperties, propertySplit)
     local finalOutput = table.concat(smwProperties, propertySplit)
   
    -- もし元の propertyValue に「など」が含まれていた場合、最終出力の末尾に追加
    if hasNado then
        -- 結合された文字列が空でない場合のみ、区切り文字を付けて「など」を追加
        if finalOutput ~= '' then
            finalOutput = finalOutput .. "など"
        else
            -- 全くプロパティが生成されなかった場合でも「など」だけ返す
            finalOutput = "など"
        end
    end
 
    return finalOutput
end
end


return p
return p