Results 1 to 3 of 3

Thread: MatchText kan niet altijd een aanwezige string vinden

  1. #1
    TDigitalTrain user Hans Brenkman's Avatar
    Join Date
    Mar 2002
    Location
    Weert
    Posts
    1,861

    MatchText kan niet altijd een aanwezige string vinden

    Hi,

    Het is nu voor de 2e keer dat ik bemerk dat MatchText (in System.StrUtils) niet doet wat die zou moeten doen. Eerder met een string zoeken in een exception (E.Message) en nu in een JSON.

    In deze JSON (RESTResponse.JSONText) kan MatchText de string "error_message" (zonder quotes) niet vinden.
    Code:
    {                "error_message":"The provided Place ID is no longer valid. Please refresh cached Place IDs as per https://developers.google.com/maps/documentation/places/web-service/place-id#save-id",
                                 "html_attributions":
                                 [
                                     ]
                               ,
                                 "status":"NOT_FOUND"
                               }
    Code:
    if System.StrUtils.MatchText( RESTResponse.JSONText, [ 'error_message', 'NOT_FOUND' ]) then
    ...
    Met
    Code:
     if AnsiContainsText( RESTResponse.JSONText, 'error_message') then 
    ...
    lukt het wel.

    MatchText is via diverse functies uiteindelijk in System.SysUtils:
    Code:
    function AnsiCompareText(const S1, S2: string): Integer;
    begin
      Result := CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, PChar(S1),
        Length(S1), PChar(S2), Length(S2)) - CSTR_EQUAL;
    end;
    ...
    Ik gebruik MatchText (case insensitive, MatchStr = case sensitive) regelmatig maar waarom dit niet goed gaat? Wie kan me vertellen wat ik over het hoofd zie?
    Testen kan niet de afwezigheid van fouten aantonen, slechts de aanwezigheid van gevonden fouten.

    Het is verdacht als een nieuw ontwikkeld programma direct lijkt te werken: waarschijnlijk neutraliseren twee ontwerpfouten elkaar.

  2. #2
    Fornicatorus Formicidae VideoRipper's Avatar
    Join Date
    Mar 2005
    Location
    Vicus Saltus Orientalem
    Posts
    5,703
    Zelf parse ik nooit JSON handmatig, maar MatchText kijkt alleen maar of, ongeacht de case, twee strings hetzelfde zijn, niet of een string in een tweede string zit.

    MatchText doet (gebruik makend van Win32 CompareString) iets soortgelijks aan dit:
    Delphi Code:
    1. If UpperCase(S1) = UpperCase(S2) then // Zijn ze identiek?
    En wat jij zoekt is iets gelijk aan dit:
    Delphi Code:
    1. if Pos(UpperCase(S1), UpperCase(S2)) > 0 then // Zit S1  in S2?

    De namen van de functies verklappen het ook wel een beetje:
    • MatchText = Komen teksten overeen
    • AnsiContainsText = Bevat tekst een tekst
    TMemoryLeak.Create(Nil);

  3. #3
    TDigitalTrain user Hans Brenkman's Avatar
    Join Date
    Mar 2002
    Location
    Weert
    Posts
    1,861

    Thumbs up

    Oeps, ja stom natuurlijk van mij.

    Dat dus over het hoofd gezien en het staat er nog wel zo duidelijk ...

    "MatchText determines if any of the strings in the array AValues match the string specified by AText using a case insensitive comparison. It returns true if at least one of the strings in the array match, or false if none of the strings match."
    Testen kan niet de afwezigheid van fouten aantonen, slechts de aanwezigheid van gevonden fouten.

    Het is verdacht als een nieuw ontwikkeld programma direct lijkt te werken: waarschijnlijk neutraliseren twee ontwerpfouten elkaar.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •