OSDN Git Service

避難所版
[gikonavigoeson/gikonavi.git] / MojuUtils.pas
index 841926c..4c87fb0 100644 (file)
@@ -32,6 +32,10 @@ uses
        //<font>\83^\83O\82ð\91S\82Ä\8dí\8f\9c\82·\82é
        function DeleteFontTag( inSource : string) : string;
        function RemoveToken(var s: string;const delimiter: string): string;
+       // \96³\8aQ\89»(& -> &amp; " -> &auot; \82É\95Ï\8a·\82·\82é)
+       function Sanitize(const s: String): String;
+       // \96³\8aQ\89»\89ð\8f\9c(&amp; -> & &auot; -> " \82É\95Ï\8a·\82·\82é)
+       function UnSanitize(const s: String): String;
 
 implementation
 // \83|\83C\83\93\83^\81[\81\95\83A\83Z\83\93\83u\83\89\82É\82æ\82é\8d\82\91¬\83|\83X
@@ -99,10 +103,10 @@ begin
     Result := StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd);
 
     while (Result <> nil) and (StrEnd - Result >= L2) do begin
-       ByteType := StrByteType(StrStart, Integer(Result-StrStart));
-       if (ByteType <> mbTrailByte) and
-               (CompareString(LOCALE_USER_DEFAULT, SORT_STRINGSORT, Result, L2, SubstrStart, L2) = 2)
-       then Exit;
+               ByteType := StrByteType(StrStart, Integer(Result-StrStart));
+               if (ByteType <> mbTrailByte) and
+                       (CompareString(LOCALE_USER_DEFAULT, SORT_STRINGSORT, Result, L2, SubstrStart, L2) = 2)
+               then Exit;
        if (ByteType = mbLeadByte) then Inc(Result);
        Inc(Result);
        Result := StrPosEx(Result, StrEnd, SubStrStart, SubStrEnd);
@@ -285,17 +289,26 @@ begin
        Result := CustomStringReplace(Result, '|', '\81b');
 end;
 (*************************************************************************
- * \96³\8cø\82ÈID\82©\82Ì\83`\83F\83b\83N\81i\96³\8cø\97á\81FID:??? , ID:???0)
+ * \96³\8cø\82ÈID\82©\82Ì\83`\83F\83b\83N\81i\96³\8cø\97á\81FID:??? , ID:???X)
  *************************************************************************)
 function IsNoValidID( inID :String): Boolean;
+var
+    bTail : Boolean;
 begin
+    Result := True;
        inID := Trim(inID);
-       if inID = '' then Result := True
-       else begin
+       if (Length(inID) > 0) then begin
                inID := Copy(inID, AnsiPos(':', inID) + 1, Length(inID) );
+        bTail := False;
+        // \96\96\94ö\82ª?\88È\8aO\82©
+        if Length(inID) > 0 then begin
+            bTail := (inID[Length(inID)] <> '?');
+        end;
                inID := CustomStringReplace(inID, '?', '');
-               if (inID = '') or (inID = '0') then Result := True
-               else Result := False;
+               if (Length(inID) > 0) and (not
+            ((Length(inID) = 1) and (bTail))) then begin
+                   Result := False;
+        end;
        end;
 end;
 
@@ -348,16 +361,35 @@ begin
        pds := PChar(delimiter);
        pde := pds + Length(delimiter);
 
-       pos := AnsiStrPosEx(pss, pse, pds, pde);
+       pos := StrPosEx(pss, pse, pds, pde);
        if pos <> nil then begin
                p := pos - pss;
                SetString(Result, pss, p);
                Delete(s, 1, p + Length(delimiter));
+        if (Length(Result) > 0) then begin
+               if (StrByteType(PChar(Result), Length(Result)-1) = mbLeadByte) then begin
+                       SetLength(Result, Length(Result) - 1);
+                   end;
+        end;
        end else begin
                Result := s;
                s := '';
        end;
 end;
 
+//! \96³\8aQ\89»(& -> &amp; " -> &quot; \82É\95Ï\8a·\82·\82é)
+function Sanitize(const s: String): String;
+begin
+    // \97]\95ª\82É\83T\83j\83^\83C\83Y\82³\82ê\82È\82¢\82æ\82¤\82É\82¢\82Á\82½\82ñ\8c³\82É\96ß\82·
+    Result := UnSanitize(s);
+       Result := CustomStringReplace(Result, '&', '&amp;');
+       Result := CustomStringReplace(Result, '"', '&quot;');
+end;
+//! \96³\8aQ\89»\89ð\8f\9c(&amp; -> & &quot; -> " \82É\95Ï\8a·\82·\82é)
+function UnSanitize(const s: String): String;
+begin
+       Result := CustomStringReplace(s, '&quot;', '"');
+       Result := CustomStringReplace(Result, '&amp;', '&');
+end;
 
 end.