Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7409241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:03:11+00:00 2026-05-29T06:03:11+00:00

I need to translate a piece of C code into Delphi/Pascal code, however I’m

  • 0

I need to translate a piece of C code into Delphi/Pascal code, however I’m having trouble understanding a couple of lines.

C Code:

static char* get_boundary(apr_pool_t* p, const char* ctype) {
  char* ret = NULL ;
  if ( ctype ) {
    char* lctype = lccopy(p, ctype) ;
    char* bdy = strstr(lctype, "boundary") ;
    if ( bdy ) {
      char* ptr = strchr(bdy, '=') ;
      if ( ptr ) {
    // what is the following line supposed to do?
    bdy = (char*) ctype + ( ptr - lctype ) + 1;
    // and this? I understand it's a loop, but *ptr and ++ptr is ugly!
    for ( ptr = bdy; *ptr; ++ptr )
      if ( *ptr == ';' || isspace(*ptr) )
        *ptr = 0 ;
    ret = apr_pstrdup(p, bdy) ;
      }
    }
  }
  return ret ;
}   

My current translation:

function get_boundary(p: Papr_pool_t; const ctype: PChar): PChar;
var
  LCType: PChar;
  LBody: PChar;
begin
  Result := NIL;
  LCType := lccopy(p, ctype);
  LBody := strpos(LCType, 'boundary');
  if LBody <> NIL then begin
    // now what? (:
  end; // if LBody <> NIL then begin
end;

lccopy is creating a copy of the ctype parameter and make it lowercase.

Some details regarding translation are highly appreciated, like ‘bdy = (char*) ctype + ( ptr – lctype ) + 1;’ and the for loop.

FYI I’m translating mod_upload.c.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:03:12+00:00Added an answer on May 29, 2026 at 6:03 am
            bdy = (char*) ctype + ( ptr - lctype ) + 1;
    

    So… ( ptr - lctype ) is pointer arithmetic to find how far into lctype ptr points. It’s the difference between the addresses held in the pointers, divided by the size of the data type they point at (in this case char, so that size is just 1).

    So bdy = (char*) ctype + ( ptr - lctype ) + 1; points bdy at the character following the '=' found previously, but in the original string ctype instead of the lowercase copy lctype.

            for ( ptr = bdy; *ptr; ++ptr )
    

    This is not a terribly strange way to iterate through a string in C. ptr points to each character while iterating through, and *ptr gives the character; so *ptr will test as FALSE when the terminating null byte is reached to end the loop. ++ptr is more pointer arithmetic to move to the pointer to the next character. Even if this seems messy, it’s a pretty natural way to do it in C.

    So the loop moves through each character of the string pointed to by bdy, and during each iteration *ptr accesses the current character.

              if ( *ptr == ';' || isspace(*ptr) )
                *ptr = 0 ;
    

    It appears the purpose of the loop was to terminate the string (by placing an earlier null terminator) at the next semicolon or whitespace character found.


    There’s enough difference between Delphi and C when it comes to string manipulation that you might be better off just figuring out what the function is doing, and then writing a Delphi equivalent from scratch rather than trying to translate it directly like this.

    It looks like the function looks for “boundary” (case insensitively) in ctype, then skips past the next “=” found, and returns a copy of everything from there up to the next semicolon or whitespace character. You could do the same thing in Delphi easily with Delphi strings and functions, using very different code if you’re willing to convert the strings first…

    Also, if it matters, it looks like the original C code ignores anything between “boundary” and “=” — so it would accept, say, “boundary asdf jidlsah;lkdsf =Value” as well as “boundary=Value“

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to translate this piece of code from Perl to Lua open(FILE, '/proc/meminfo');
I need to translate some python and java routines into pseudo code for my
I have the following app.config section that I need to translate into code. I
I need to translate the a carbon method into cocoa into and I am
We have a requirement that every piece of code that makes it into production
I need to translate this C code to MIPS assembly. Here is the C
I need to translate a linux batch file into a windows bat file. for
I need to translate result strings from a library into exceptions. Each string has
I need to translate the following Code to an Expression and I will explain
I need to translate this into Objective-C, can anyone help ? var randomString =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.